Yes/No Statement
I want to know how to make it a yes or no statement.
How to make it Yes I want to buy the shield,
or no then NOT buy it
Any help please?
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
|
#include <iostream>
#include <string>
using namespace std;
int gold = 30000;
char buy;
int main ()
{
string buy;
const int MAX_ITEMS = 10;
string inventory[MAX_ITEMS];
int numItems = 0;
inventory[numItems ++] = "Sword";
inventory[numItems ++] = "Armor";
inventory[numItems ++] = "Shield";
cout << "Your item:\n";
for (int i = 0; i < numItems; ++i)
cout << inventory [i] << endl;
cout << "\nYou trade your Sword for a Battle Axe.";
inventory [0] = "Battle Axe";
cout << "\nYour items:\n";
for (int i = 0; i < numItems; ++i)
cout << inventory [i] << endl;
cout << "Would you like to buy this Shield? Its only 30000 Gold Pieces! (y/n): ";
cin >> buy;
if (buy == 'y')
{
if (gold < 30000)
cout << "You dont have enough Gold!";
}
cout << "You have bought an Elder Shield!"endl;
inventory [numItems ++] = "Elder Shield";
for (int i = 2; i < numItems; ++i)
cout << inventory [i] << endl;
cout << "\nYou find a Healing Potion!";
if (numItems < MAX_ITEMS)
inventory [numItems ++] = "Healing Potion";
else
cout << "You have too many items and can't carry another.";
cout << "\nYour items:\n";
for (int i = 0; i < numItems; ++i)
cout << inventory [i] << endl;
system ("pause");
return 0;
}}
| |
Place lines 37 and 38 in an else statement after line 35.
It says that line 32 no match for 'operator==' in 'buy == 'y''. Any suggestions?
Put quotes around the y
if (buy == "y")
Topic archived. No new replies allowed.