Need help with errors

I don't understand the errors I'm getting

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

31 Replies - 1502 Views - Last Post: 29 November 2009 - 06:11 PM Rate Topic: -----

#1 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Need help with errors

Posted 02 October 2009 - 06:33 PM

#include <iostream>
using namespace std;
 
class PlasmaPistolClass{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;

//member function prototypes

void pressTrigger(void);
void load(int nmbrOfBolts);
void setDestructivePower(int powerSetting);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void); 
//constructors
PlasmaPistolClass();	//a default constructor that assigns default values to both
						//the private and public properties
PlasmaPistolClass(int, int);  //An overload constructor that allows the destructive
							  //power and maxAmmo properties to be set when the object is instatiated	
};

int main(void){


	PlasmaPistolClass plasmaPistol2(int, int);
cout << "Destructive Power : "   << plasmaPistol2.showDestructivePower() << endl;
cout << "Number of bolts left : "  << plasmaPistol2.ammoRemaining() << endl;
cout << "Rate of fire : "  << plasmaPistol2.showRateOfFire() << endl; 
cout << endl;
cout << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol2.ammoRemaining  << endl;

return 0;
}

//these are the plasmaPistols methods
void PlasmaPistolClass:: pressTrigger(void){							   //fires the plasma pistol and decreases the ammo count based									   
	if (safetyOn != true){
		if (theRateOfFire <= theAmmo){
			cout << "Plasma Pistol Fired";
			theAmmo -= theRateOfFire;
		}
		else{																	//on the rateOfFire property. The pistol should not fire if 																			   //theSafetyOn property is true.
			cout << "Plasma Pistol does not have enough ammo to fire";		 // the safety is on
		}
	else{
		cout << "Plasma Pistol safety is on";
	}
		
}
	   									
	void PlasmaPistolClass::load(int nmbrOfBolts){
		theAmmo += nmbrOfBolts;
			if (theaAmmo > maxAmmo)
				theAmmo = maxAmmo;
	}														//adds ammo bolts to the plasma pistol. The amount of ammo bolts
													   //in the plasma pistol can not exceed theMaxAmmo property

	void PlasmaPistolClass::setDestructivePower(int powerSetting){
			if (powerSetting < 1)
				theDestructivePower =1;
			else if (powerSetting > 10)
				theDestructivePower = 10;
	}													//changes the destructive power of the plasma pistol

	int PlasmaPistolClass::showDestructivePower(void){
		return theDestructivePower;
	}													//returns the value of theDestructivePower property

	void PlasmaPistolClass::setRateOfFire(int boltsPerTriggerPress){ 
		if (boltsPerTriggerPress < 1)
			theRateOfFire = 1;
		else if
			(boltsPerTriggerPress > 10)
			 theRateOfFire = 10;
	}												

	int PlasmaPistolClass::showRateOfFire(void){ 
		return theRateOfFire;
	}													//returns the value of theRateOfFire property

	int PlasmaPistolClass::ammoRemaining(void){
		return theAmmo;
	}													//returns the amount of ammo remaining in the pistol







Here are the errors

Error 7 error C2181: illegal else without matching if c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 64
Error 2 error C2228: left of '.ammoRemaining' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 41
Error 6 error C2228: left of '.ammoRemaining' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 49
Error 1 error C2228: left of '.showDestructivePower' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 40
Error 3 error C2228: left of '.showRateOfFire' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 42
Error 4 error C2228: left of '.showRateOfFire' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 45
Error 5 error C2228: left of '.showRateOfFire' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 46
Error 13 error C2601: 'PlasmaPistolClass::ammoRemaining' : local function definitions are illegal c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 101
Error 8 error C2601: 'PlasmaPistolClass::load' : local function definitions are illegal c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 71
Error 9 error C2601: 'PlasmaPistolClass::setDestructivePower' : local function definitions are illegal c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 78
Error 11 error C2601: 'PlasmaPistolClass::setRateOfFire' : local function definitions are illegal c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 89
Error 10 error C2601: 'PlasmaPistolClass::showDestructivePower' : local function definitions are illegal c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 85
Error 12 error C2601: 'PlasmaPistolClass::showRateOfFire' : local function definitions are illegal c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 97
Error 14 fatal error C1075: end of file found before the left brace '{' at 'c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp(55)' was matched c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 106


any help would be appreciated

Is This A Good Question/Topic? 0
  • +

Replies To: Need help with errors

#2 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 06:39 PM

knocked it down found some of the errors here are the errors remaining

Error 2 error C2228: left of '.ammoRemaining' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 41
Error 6 error C2228: left of '.ammoRemaining' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 49
Error 1 error C2228: left of '.showDestructivePower' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 40
Error 3 error C2228: left of '.showRateOfFire' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 42
Error 4 error C2228: left of '.showRateOfFire' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 45
Error 5 error C2228: left of '.showRateOfFire' must have class/struct/union c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 46
Was This Post Helpful? 0
  • +
  • -

#3 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Need help with errors

Posted 02 October 2009 - 06:48 PM

Um.. this line:
PlasmaPistolClass plasmaPistol2(int, int);


That isn't going to cut it. You have to pass in a real integer not just a keyword.
Was This Post Helpful? 0
  • +
  • -

#4 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 07:15 PM

ok I'll try that

did that and I got these 2 errors

Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\HP_Administrator.WILSON\My Documents\Visual Studio 2008\Projects\WilsonIII_Lab5_exercise1\Debug\WilsonIII_Lab5_exercise1.exe
Error 1 error LNK2019: unresolved external symbol "public: __thiscall PlasmaPistolClass::PlasmaPistolClass(int,int,int)" (??0PlasmaPistolClass@@QAE@HHH@Z) referenced in function _main WilsonIII_Lab5_exercise1.obj
Was This Post Helpful? 0
  • +
  • -

#5 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Need help with errors

Posted 02 October 2009 - 07:26 PM

Post your current code.
Was This Post Helpful? 0
  • +
  • -

#6 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 07:36 PM

#include <iostream>
using namespace std;
 
class PlasmaPistolClass{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;

//member function prototypes

void pressTrigger(void);
void load(int nmbrOfBolts);
void setDestructivePower(int powerSetting);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void); 
//constructors
PlasmaPistolClass();	//a default constructor that assigns default values to both
						//the private and public properties
PlasmaPistolClass(int, int, int);  //An overload constructor that allows the destructive
							  //power and maxAmmo properties to be set when the object is instatiated	
};

int main(void){


	PlasmaPistolClass plasmaPistol2(50, 9, 7);
cout << "Destructive Power : "   << plasmaPistol2.showDestructivePower() << endl;
cout << "Number of bolts left : "  << plasmaPistol2.ammoRemaining() << endl;
cout << "Rate of fire : "  << plasmaPistol2.showRateOfFire() << endl; 
cout << endl;
cout << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol2.ammoRemaining()  << endl;

return 0;
}


//these are the plasmaPistols methods
void PlasmaPistolClass:: pressTrigger(void){							   //fires the plasma pistol and decreases the ammo count based									   
	if (safetyOn != true){
		if (theRateOfFire <= theAmmo){
			cout << "Plasma Pistol Fired";
			theAmmo -= theRateOfFire;
		}
		else{																	//on the rateOfFire property. The pistol should not fire if 																			   //theSafetyOn property is true.
			cout << "Plasma Pistol does not have enough ammo to fire or the plasma pistols safety is on";		 // the safety is on
		}
	
	
	}
		
}
	   									
	void PlasmaPistolClass::load(int nmbrOfBolts){
		theAmmo += nmbrOfBolts;
			if (theAmmo > maxAmmo)
				theAmmo = maxAmmo;
	}														//adds ammo bolts to the plasma pistol. The amount of ammo bolts
													   //in the plasma pistol can not exceed theMaxAmmo property

	void PlasmaPistolClass::setDestructivePower(int powerSetting){
			if (powerSetting < 1)
				theDestructivePower =1;
			else if (powerSetting > 10)
				theDestructivePower = 10;
	}													//changes the destructive power of the plasma pistol

	int PlasmaPistolClass::showDestructivePower(void){
		return theDestructivePower;
	}													//returns the value of theDestructivePower property

	void PlasmaPistolClass::setRateOfFire(int boltsPerTriggerPress){ 
		if (boltsPerTriggerPress < 1)
			theRateOfFire = 1;
		else if
			(boltsPerTriggerPress > 10)
			 theRateOfFire = 10;
	}												

	int PlasmaPistolClass::showRateOfFire(void){ 
		return theRateOfFire;
	}													//returns the value of theRateOfFire property

	int PlasmaPistolClass::ammoRemaining(void){
		return theAmmo;
	}													//returns the amount of ammo remaining in the pistol





here are the 2 errors again

Error 2 fatal error LNK1120: 1 unresolved externals C:\Documents and Settings\HP_Administrator.WILSON\My Documents\Visual Studio 2008\Projects\WilsonIII_Lab5_exercise1\Debug\WilsonIII_Lab5_exercise1.exe
Error 1 error LNK2019: unresolved external symbol "public: __thiscall PlasmaPistolClass::PlasmaPistolClass(int,int,int)" (??0PlasmaPistolClass@@QAE@HHH@Z) referenced in function _main WilsonIII_Lab5_exercise1.obj
Was This Post Helpful? 0
  • +
  • -

#7 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Need help with errors

Posted 02 October 2009 - 07:45 PM

You need to actually write code for the constructor. You can't call a non-existent function.
Was This Post Helpful? 0
  • +
  • -

#8 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 07:46 PM

I got the lnk2019 error before because I miss spelled something, but I'm not seeing the error, and the other error I don't understand

View Posteker676, on 2 Oct, 2009 - 06:45 PM, said:

You need to actually write code for the constructor. You can't call a non-existent function.




are you saying the default constructor?
Was This Post Helpful? 0
  • +
  • -

#9 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: Need help with errors

Posted 02 October 2009 - 07:47 PM

^ Look above.

You have no defined constructor for int, int, int or for the default constructor.
Was This Post Helpful? 0
  • +
  • -

#10 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 08:24 PM

#include <iostream>
using namespace std;
 
class PlasmaPistol{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;

//member function prototypes

void pressTrigger(void);
void load(int);
void setDestructivePower(int);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void); 
//constructors
PlasmaPistolClass();	//a default constructor that assigns default values to both
						//the private and public properties
PlasmaPistolClass(int, int,);  //An overload constructor that allows the destructive
							  //power and maxAmmo properties to be set when the object is instatiated	
};

int main(void){

PlasmaPistolClass plasmaPistol1;//uses the default constructor
PlasmaPistolClass plasmaPistol2(7, 50);//uses the overloaded constructor 

cout << "Plasma Pistol 1's Destructive Power : "   << plasmaPistol1.showDestructivePower() << endl;
cout << "Plasma Pistol 1's Number of bolts left : "  << plasmaPistol1.ammoRemaining() << endl;
cout << "Plasma Pistol 1's Rate of fire : "  << plasmaPistol1.showRateOfFire() << endl; 
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol1.ammoRemaining()  << endl;
cout << endl;
cout << endl;
cout << "Plasma Pistol 2's Destructive Power : "   << plasmaPistol2.showDestructivePower() << endl;
cout << "Plasma Pistol 2's Number of bolts left : "  << plasmaPistol2.ammoRemaining() << endl;
cout << "Plasma Pistol 2's Rate of fire : "  << plasmaPistol2.showRateOfFire() << endl; 
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol2.ammoRemaining()  << endl;

return 0;
}

PlasmaPistol::PlasmaPistol(){
	int theAmmo = 56;
	int theRateOfFire = 5;
	int theDestructivePower = 9;
	bool safetyOn = false;
	int maxAmmo = 100;
}

PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
	int theDestructivePower = powerSetting;
	int maxAmmo = nmbrOfBolts;
}
//these are the plasmaPistols methods
void PlasmaPistolClass:: pressTrigger(void){							   //fires the plasma pistol and decreases the ammo count based									   
	if (safetyOn != true){
		if (theRateOfFire <= theAmmo){
			cout << "Plasma Pistol Fired";
			theAmmo -= theRateOfFire;
		}
		else{																	//on the rateOfFire property. The pistol should not fire if 																			   //theSafetyOn property is true.
			cout << "Plasma Pistol does not have enough ammo to fire or the plasma pistols safety is on";		 // the safety is on
		}
	
	
	}
		
}
	   									
	void PlasmaPistolClass::load(int nmbrOfBolts){
		theAmmo += nmbrOfBolts;
			if (theAmmo > maxAmmo)
				theAmmo = maxAmmo;
	}														//adds ammo bolts to the plasma pistol. The amount of ammo bolts
													   //in the plasma pistol can not exceed theMaxAmmo property

	void PlasmaPistolClass::setDestructivePower(int powerSetting){
			if (powerSetting < 1)
				theDestructivePower =1;
			else if (powerSetting > 10)
				theDestructivePower = 10;
	}													//changes the destructive power of the plasma pistol

	int PlasmaPistolClass::showDestructivePower(void){
		return theDestructivePower;
	}													//returns the value of theDestructivePower property

	void PlasmaPistolClass::setRateOfFire(int boltsPerTriggerPress){ 
		if (boltsPerTriggerPress < 1)
			theRateOfFire = 1;
		else if
			(boltsPerTriggerPress > 10)
			 theRateOfFire = 10;
	}												

	int PlasmaPistolClass::showRateOfFire(void){ 
		return theRateOfFire;
	}													//returns the value of theRateOfFire property

	int PlasmaPistolClass::ammoRemaining(void){
		return theAmmo;
	}													//returns the amount of ammo remaining in the pistol




I'm getting many errors now need some major help

how do I get rid of this error?

Error 1 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 30
Was This Post Helpful? 0
  • +
  • -

#11 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 08:29 PM

nevermind figured it out;)
just cleaning errors now
Was This Post Helpful? 0
  • +
  • -

#12 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Need help with errors

Posted 02 October 2009 - 08:30 PM

So what did you try in your attempts to fix this error? (I'm curious, what do you do when you see an error you don't know how to deal with?)

This post has been edited by Oler1s: 02 October 2009 - 08:30 PM

Was This Post Helpful? 0
  • +
  • -

#13 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 08:35 PM

need help got 2 errors here is the code
#include <iostream>
using namespace std;
 
class PlasmaPistol{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;

//member function prototypes

void pressTrigger(void);
void load(int);
void setDestructivePower(int);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void); 
//constructors
PlasmaPistol();	//a default constructor that assigns default values to both
					//the private and public properties.
PlasmaPistol(int, int,);  //An overload constructor that allows the destructive
													  
							  //power and maxAmmo properties to be set when the object is instatiated	
};

int main(void){

PlasmaPistol plasmaPistol1;//uses the default constructor
PlasmaPistol plasmaPistol2(7, 50);//uses the overloaded constructor 

cout << "Plasma Pistol 1's Destructive Power : "   << plasmaPistol1.showDestructivePower() << endl;
cout << "Plasma Pistol 1's Number of bolts left : "  << plasmaPistol1.ammoRemaining() << endl;
cout << "Plasma Pistol 1's Rate of fire : "  << plasmaPistol1.showRateOfFire() << endl; 
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol1.ammoRemaining()  << endl;
cout << endl;
cout << endl;
cout << "Plasma Pistol 2's Destructive Power : "   << plasmaPistol2.showDestructivePower() << endl;
cout << "Plasma Pistol 2's Number of bolts left : "  << plasmaPistol2.ammoRemaining() << endl;
cout << "Plasma Pistol 2's Rate of fire : "  << plasmaPistol2.showRateOfFire() << endl; 
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol2.ammoRemaining()  << endl;

return 0;
}

PlasmaPistol::PlasmaPistol(){
	int theAmmo = 56;
	int theRateOfFire = 5;
	int theDestructivePower = 9;
	bool safetyOn = false;
	int maxAmmo = 100;
}

PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
	int theDestructivePower = powerSetting;
	int maxAmmo = nmbrOfBolts;
}
//these are the plasmaPistols methods
void PlasmaPistol:: pressTrigger(void){							   //fires the plasma pistol and decreases the ammo count based									   
	if (safetyOn != true){
		if (theRateOfFire <= theAmmo){
			cout << "Plasma Pistol Fired";
			theAmmo -= theRateOfFire;
		}
		else{																	//on the rateOfFire property. The pistol should not fire if 																			   //theSafetyOn property is true.
			cout << "Plasma Pistol does not have enough ammo to fire or the plasma pistols safety is on";		 // the safety is on
		}
	
	
	}
		
}
	   									
	void PlasmaPistol::load(int nmbrOfBolts){
		theAmmo += nmbrOfBolts;
			if (theAmmo > maxAmmo)
				theAmmo = maxAmmo;
	}														//adds ammo bolts to the plasma pistol. The amount of ammo bolts
													   //in the plasma pistol can not exceed theMaxAmmo property

	void PlasmaPistol::setDestructivePower(int powerSetting){
			if (powerSetting < 1)
				theDestructivePower =1;
			else if (powerSetting > 10)
				theDestructivePower = 10;
	}													//changes the destructive power of the plasma pistol

	int PlasmaPistol::showDestructivePower(void){
		return theDestructivePower;
	}													//returns the value of theDestructivePower property

	void PlasmaPistol::setRateOfFire(int boltsPerTriggerPress){ 
		if (boltsPerTriggerPress < 1)
			theRateOfFire = 1;
		else if
			(boltsPerTriggerPress > 10)
			 theRateOfFire = 10;
	}												

	int PlasmaPistol::showRateOfFire(void){ 
		return theRateOfFire;
	}													//returns the value of theRateOfFire property

	int PlasmaPistol::ammoRemaining(void){
		return theAmmo;
	}													//returns the amount of ammo remaining in the pistol





here are the errors

Error 2 error C2143: syntax error : missing ')' before ';' c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 32
Error 1 error C2059: syntax error : ')' c:\documents and settings\hp_administrator.wilson\my documents\visual studio 2008\projects\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1\wilsoniii_lab5_exercise1.cpp 32
Was This Post Helpful? 0
  • +
  • -

#14 Oler1s  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1395
  • View blog
  • Posts: 3,884
  • Joined: 04-June 09

Re: Need help with errors

Posted 02 October 2009 - 08:36 PM

I again ask you, what have you tried?
Was This Post Helpful? 0
  • +
  • -

#15 Gmoney93079  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 256
  • Joined: 19-September 09

Re: Need help with errors

Posted 02 October 2009 - 08:46 PM

farkle got it to build but not getting correct output I have a logic error somewhere grrrrr

#include <iostream>
using namespace std;
 
class PlasmaPistol{
private:
//properties
int theAmmo;
int theRateOfFire;
int theDestructivePower;
public:
//properties
bool safetyOn;
int maxAmmo;

//member function prototypes

void pressTrigger(void);
void load(int);
void setDestructivePower(int);
int showDestructivePower(void);
void setRateOfFire (int boltsPerTriggerPress);
int showRateOfFire(void);
int ammoRemaining(void); 
//constructors
PlasmaPistol();										//a default constructor that assigns default values to both
PlasmaPistol(int, int);											//the private and public properties.
											//An overload constructor that allows the destructive
											   //power and maxAmmo properties to be set when the object is instatiated
};

int main(void){

PlasmaPistol plasmaPistol1;//uses the default constructor
PlasmaPistol plasmaPistol2(7, 50);//uses the overloaded constructor 

cout << "Plasma Pistol 1's Destructive Power : "   << plasmaPistol1.showDestructivePower() << endl;
cout << "Plasma Pistol 1's Number of bolts left : "  << plasmaPistol1.ammoRemaining() << endl;
cout << "Plasma Pistol 1's Rate of fire : "  << plasmaPistol1.showRateOfFire() << endl; 
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol1.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol1.ammoRemaining()  << endl;
cout << endl;
cout << endl;
cout << "Plasma Pistol 2's Destructive Power : "   << plasmaPistol2.showDestructivePower() << endl;
cout << "Plasma Pistol 2's Number of bolts left : "  << plasmaPistol2.ammoRemaining() << endl;
cout << "Plasma Pistol 2's Rate of fire : "  << plasmaPistol2.showRateOfFire() << endl; 
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << "Shooting " << plasmaPistol2.showRateOfFire() << "bolts "  << endl;
cout << endl;
cout << endl;
cout << "Number of bolts left: " << plasmaPistol2.ammoRemaining()  << endl;

return 0;
}

PlasmaPistol::PlasmaPistol(){
	int theAmmo = 56;
	int theRateOfFire = 5;
	int theDestructivePower = 9;
	bool safetyOn = false;
	int maxAmmo = 100;
}

PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
	int theDestructivePower = powerSetting;
	int maxAmmo = nmbrOfBolts;
}
//these are the plasmaPistols methods
void PlasmaPistol:: pressTrigger(void){							   //fires the plasma pistol and decreases the ammo count based									   
	if (safetyOn != true){
		if (theRateOfFire <= theAmmo){
			cout << "Plasma Pistol Fired";
			theAmmo -= theRateOfFire;
		}
		else{																	//on the rateOfFire property. The pistol should not fire if 																			   //theSafetyOn property is true.
			cout << "Plasma Pistol does not have enough ammo to fire or the plasma pistols safety is on";		 // the safety is on
		}
	
	
	}
		
}
	   									
	void PlasmaPistol::load(int nmbrOfBolts){
		theAmmo += nmbrOfBolts;
			if (theAmmo > maxAmmo)
				theAmmo = maxAmmo;
	}														//adds ammo bolts to the plasma pistol. The amount of ammo bolts
													   //in the plasma pistol can not exceed theMaxAmmo property

	void PlasmaPistol::setDestructivePower(int powerSetting){
			if (powerSetting < 1)
				theDestructivePower =1;
			else if (powerSetting > 10)
				theDestructivePower = 10;
	}													//changes the destructive power of the plasma pistol

	int PlasmaPistol::showDestructivePower(void){
		return theDestructivePower;
	}													//returns the value of theDestructivePower property

	void PlasmaPistol::setRateOfFire(int boltsPerTriggerPress){ 
		if (boltsPerTriggerPress < 1)
			theRateOfFire = 1;
		else if
			(boltsPerTriggerPress > 10)
			 theRateOfFire = 10;
	}												

	int PlasmaPistol::showRateOfFire(void){ 
		return theRateOfFire;
	}													//returns the value of theRateOfFire property

	int PlasmaPistol::ammoRemaining(void){
		return theAmmo;
	}													//returns the amount of ammo remaining in the pistol





output yikes!!!!!

Plasma Pistol 1's Destructive Power : -858993460
Plasma Pistol 1's Number of bolts left : -858993460
Plasma Pistol 1's Rate of fire : -858993460
Shooting -858993460bolts
Shooting -858993460bolts


Number of bolts left: -858993460


Plasma Pistol 2's Destructive Power : -858993460
Plasma Pistol 2's Number of bolts left : -858993460
Plasma Pistol 2's Rate of fire : -858993460
Shooting -858993460bolts
Shooting -858993460bolts


Number of bolts left: -858993460
Press any key to continue . . .

out put should be similar to this

Destructive Power : 5
Number of bolts left : 30
Rate of fire : 5

Shooting 5 bolts
Shooting 5 bolts

Number of bolts left: 20
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3