   shop simulator
  I have made a shop simulator but i has 88 errors i dont know ycan u help?#include <iostream>#include <string>using namespace std;int main(void){string helmet, sword, shield, armour;string purchase;int money = 200;int costH = 35;int costSw = 50;int costSh = 40;int costA = 60;int total;char choice;int amountH, amountSw, amountSh, amountA;bool quit = false;cout << "Welcome to Alex's Dungeon shop." << endl;cout << "You have $200." << endl;cout << "In this shop you can buy helmets, swords, shields and armour." << endl;while (quit==false);{cout << "What would you like to buy (eg. helmet): " << endl;cin >> purchase;{    if (purchase == 'helmet');{cout << "Each helmet costs $35." << endl;cout << "How many helmets would you like: " << endl;cin >> amountH;total = amountH * costH;cout << "The total cost is $" << total << " " << endl;money = money - total;    cout << "You have $" << money << " left." << endl;}else if (purchase == 'sword');{cout << "Each sword costs $50." << endl;cout << "How many swords would you like: " << endl;cin >> amountSw;total = amountSw * costSw;cout << "The total cost is $" << total << " " << endl;money = money - total;    cout << "You have $" << money << " left." << endl;}else if (purchase == 'shield');{cout << "Each shield costs $40." << endl;cout << "How many shields would you like: " << endl;cin >> amountSh;total = amountSh * costSh;cout << "The total cost is $" << total << " " << endl;money = money - total;  cout << "You have $" << money << " left." << endl;}else if (purchase == 'armour');{cout << "Each armour costs $60." << endl;cout << "How many armour would you like: " << endl;cin >> amountA;total = amountA * costA;cout << "The total cost is $" << total << " " << endl;money = money - total;cout << "You have $" << money << " left." << endl;}else{cout << "That item does not exist." << endl;return 0;}}}cout << "Type Q to quit else press any other key: " << endl;cin >> choice;if (choice=='Y')quit = false;else quit = true;return 0;}    
  First of all, you should either #include <cstring> or #include <string.h> - I think that causes a lot of your errors, but if there are still errors, it would be nice if you'd post some of them here so it's easier to spot them ;)   ;Quote:Original post by bxela1if (purchase == 'helmet');String literals like this must be encased in double quotes, eg "helmet" rather than 'helmet'.if statements are not (generally) followed by a semi-colon.In future, you should quote the exact error message received, to make things easier to debug.   ;  it has something wrong with "=="and it says i have an else without if.i fixed literals but it still has a problem with a binary error regarding cin >> purchase   ;  OK, I ran it myself and I have a few other things to point out.I saw you put a delimiter ';' behind every right bracket of an if statement. This is not necessary and I believe it caused the errors with 'else' that you stated. Furthermore, I got this error two times:error C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::alThis is because you use cin >> on a string once. You really should use cin.getline() if you wanted to get a whole string from the user.Also, when comparing strings, if you are comparing to a string between double quotes you have to make it a c-style string, using the c_str() method that comes with the string object.I've rewritten some things, and this should work...#include <iostream>#include <string.h>using namespace std;int main(void){    string helmet, sword, shield, armour;    string purchase;    int money = 200;    int costH = 35;    int costSw = 50;    int costSh = 40;    int costA = 60;    int total;    char choice;    int amountH, amountSw, amountSh, amountA;    bool quit = false;    cout << "Welcome to Alex's Dungeon shop." << endl;    cout << "You have $200." << endl;    cout << "In this shop you can buy helmets, swords, shields and armour." << endl;    while (quit==false){   cout << "What would you like to buy (eg. helmet): " << endl;   cin.getline ( (char *)purchase.c_str(), 20 );   if ( purchase.c_str() == "helmet" ) {  cout << "Each helmet costs $35." << endl;  cout << "How many helmets would you like: " << endl;  cin >> amountH;  total = amountH * costH;  cout << "The total cost is $" << total << " " << endl;  money = money - total;  cout << "You have $" << money << " left." << endl;} else if (purchase.c_str() == "sword") {  cout << "Each sword costs $50." << endl;  cout << "How many swords would you like: " << endl;  cin >> amountSw;  total = amountSw * costSw;  cout << "The total cost is $" << total << " " << endl;  money = money - total;  cout << "You have $" << money << " left." << endl;} else if (purchase.c_str() == "shield") {cout << "Each shield costs $40." << endl;cout << "How many shields would you like: " << endl;cin >> amountSh;total = amountSh * costSh;cout << "The total cost is $" << total << " " << endl;money = money - total;cout << "You have $" << money << " left." << endl;} else if (purchase.c_str() == "armour") {cout << "Each armour costs $60." << endl;cout << "How many armour would you like: " << endl;cin >> amountA;total = amountA * costA;cout << "The total cost is $" << total << " " << endl;money = money - total;cout << "You have $" << money << " left." << endl;} else {cout << "That item does not exist." << endl;return 0;}}    cout << "Type Q to quit else press any other key: " << endl;cin >> choice;if (choice == 'Y')quit = false;else quit = true;return 0;};  i fixed it but i doesnt go past: you can buy helmets, swords eg.   ;Quote:Original post by rogierpenninkerror C2679: binary '>>' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::alFunny, this part compiled fine for me (using g++).Quote:This is because you use cin >> on a string once. You really should use cin.getline() if you wanted to get a whole string from the user.In fact, you'd be better off using the free function "getline", which takes a std::string as a parameters. Your version, using cin.getline, will not work since c_str returns a const char *, and you are trying to write to it. If you do use either of these methods however, you'll need to replace all of your "cin >>" lines with them.You're best off sticking with "cin >> purchase" etc, which will work if you include the correct header, <string> rather than <string.h>.Quote:Also, when comparing strings, if you are comparing to a string between double quotes you have to make it a c-style string, using the c_str() method that comes with the string object.Completely untrue, and will not work. You'll then be comparing the address of the temporary string with the string literal.In summary, did you even bother to test your "corrected" version?   ;  To make rogierpennink's version work, replacecin.getline ( (char *)purchase.c_str(), 20 ); with getline(cin, purchase); and remove the ".c_str()" calls from the if statements.Also, change the incluse back to #include <string> rather than <string.h> - you had it right initially.   ;Quote:Completely untrue, and will not work. You'll then be comparing the address of the temporary string with the string literal.Well that is strange, because if I don't use c_str() I get to see this:error C2676: binary '==' : 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' does not define this operator or a conversion to a type acceptable to the predefined operatorIf I use it I have no errors except two linker errors which leads me to believe that there is still something wrong, although I can't directly relate it to this string comparison thing... :SEdit: I tested your suggestion after your initial post but I'm still getting the same linker errors...   ;  You're getting the undefined symbol errors because you are including <string.h> instead of <string>.What linker errors are you getting?   