#include <iostream>
using namespace std;
class Relic {
public:
string Type;
int Price;
};
int main()
{
Relic relicNeo;
relicNeo.Type = "Neo";
relicNeo.Price = 50;
Relic relicLith;
relicLith.Type = "Lith";
relicLith.Price = 20;
bool canPurchase = true;
int plat;
string answer;
cout << "Enter your platinum: " << endl;
cin >> plat;
while(bool canPurchase = true){
cout << " " << endl;
cout << "Would you like to purchase another relic?n" << endl;
cout << "Neo Relic: 50 Plat (1)" << endl;
cout << "Lith Relic: 20 Plat (2)" << endl;
cin >> answer;
if(answer == "2" && plat >= relicLith.Price){
plat = plat - relicLith.Price;
cout << "Relic Purchased n" << endl;
cout << "New plat Balance: " << plat << endl;
}else if(plat < relicLith.Price){
bool canPurchase = false;
cout << "You don't have enough to purchase" << endl;
return 0;
}
if(plat == 0){
return 0;
}
if(answer == "1" && plat >= relicNeo.Price){
plat = plat - relicNeo.Price;
cout << "Relic Purchased n" << endl;
cout << "New plat Balance: " << plat << endl;
}else if(plat < relicNeo.Price){
bool canPurchase = false;
cout << "You don't have enough to purchase" << endl;
return 0;
}
if(plat == 0){
return 0;
}
}
return 0;
}
So, I have two identical lines of code, only difference is the relic, when I put my plat as 200, i can buy neo(50) 4 times until m balance is 0, if i put my balance at 80, i can buy lith(20) until my balance is less than that of neo (50), however i’ve looked at it and do not understand why it’s like that. I’m super new to c++ btw.
New contributor
Daniel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.