with output error in code or my logic

here is my 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 powerSetting);
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(){
theAmmo = 56;
theRateOfFire = 5;
theDestructivePower = 9;
safetyOn = false;
maxAmmo = 100;
}

PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
theDestructivePower = powerSetting;
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;
theAmmo += 50;
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){
theDestructivePower = powerSetting;
if (theDestructivePower < 1)
theDestructivePower = 1;
else if (theDestructivePower > 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){
theRateOfFire = 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 is the output I'm getting:

Plasma Pistol 1's Destructive Power : 9
Plasma Pistol 1's Number of bolts left : 56
Plasma Pistol 1's Rate of fire : 5
Shooting 5bolts
Shooting 5bolts


Number of bolts left: 56


Plasma Pistol 2's Destructive Power : 7
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 . . .

I need plasma pistol 2 to look like plasma pistol 1 and I'm stuck and so are my other friends any help is greatly appreciated;)
Wrap the code in code tags ([code][/code]).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122

#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 powerSetting);
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(){
theAmmo = 56;
theRateOfFire = 5;
theDestructivePower = 9;
safetyOn = false;
maxAmmo = 100;
}

PlasmaPistol::PlasmaPistol(int powerSetting, int nmbrOfBolts){
theDestructivePower = powerSetting;
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;
theAmmo += 50;
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){
theDestructivePower = powerSetting;
if (theDestructivePower < 1)
theDestructivePower = 1;
else if (theDestructivePower > 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){ 
theRateOfFire = 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 
Topic archived. No new replies allowed.