this code keeps giving me input errors i tired every thing that i know of to fix it but the problem remains what im i doing wrong at the end of the code?
#include <iostream>usingnamespace std;
{
public:
// The player will have potions and gold variablesint potions;
int gold;
int HamGranade;
// You can also have variables to describe the player's race, class, and name// But for now, we'll keep it simplepublic:
player( int p, int g,int h )
{
// Set potions and gold
potions = p;
gold = g;
HamGranade = h;
// Notify the console:
cout << "Player was created with " << potions << " potions and " << gold << " gold." << endl;
}
~player()
{
cout << "Player was destroyed :.(" << endl;
}
void display_status()
{
cout << "You have " << gold << " gold and " << potions << " potions" << endl;
cout << "You have " << HamGranade <<"Ham Granades"<<endl;
}
};
class store
{
private:
// The members of a store object// Note, this is listed under "private," which means that only the functions below can access this variableint potions_in_stock;
int Ham_in_stock;
public:
// The constructor
store( int num_potions,int num_Ham )
{
// Stock up on potions!
potions_in_stock = num_potions;
Ham_in_stock = num_Ham;
cout << "A store was created with " << potions_in_stock << " potions in stock." << endl;
cout << Ham_in_stock <<"HamGranades"<< endl;
}
// The destructor
~store()
{
cout << "The store was destroyed :.(" << endl;
}
// The player parameter is to specify which player is entering this store// The '&' stands for "reference to" which means that we'll directly be// modifying the player, and not a copy of it. // by changing it to "player the_player" we're going to be working with // a copy of the player that is passed, which isn't what we want, we want// to modify the object itself.void player_enters( player &the_player )
{
// Welcome message
cout << endl;
cout << "Welcome to my store!" << endl;
// Check to see if we have some potions:if ( potions_in_stock == 0 )
{
// We don't
cout << "Unfortunately, I'm out of potions!" << endl;
}
if ( Ham_in_stock == 0 )
{
// We don't
cout << "Unfortunately, I'm out of Ham's!" << endl;
}
elseif ( the_player.gold < 5 )
{
// He/she doesn't have money
cout << "Unfortunately, you requires more moneys" << endl;
}
else
{
bool player_is_still_buying = true;
while ( player_is_still_buying && potions_in_stock > 0 ||player_is_still_buying && Ham_in_stock > 0)
{
// Display player's status:
cout << endl;
the_player.display_status();
if ( the_player.gold < 5 )
{
cout << "Looks like you're out of money lol" << endl;
player_is_still_buying = false;
break; // Force out of the "while" loop
}
cout << endl;
cout << "What would you like to buy?" << endl;
cout << "1) Potion (" << potions_in_stock << ")" << endl;
cout << "2) Ham Granades (" << Ham_in_stock << ")" << endl;
cout << "3) Leave" << endl;
cout << endl;
cout << "Enter choice: ";
// Get a choice from the userint choice;
cin >> choice;
if ( choice == 3 ) // Player decides to leave
player_is_still_buying = false;
else
{
// Player decides not to leaveif ( choice == 1 ) // Player decides to buy a potion
{
the_player.gold -= 5; // Subtract the money out of the player
the_player.potions += 1; // Add a potion to the player
potions_in_stock -= 1; // Subtract a potion out of the store's stockif ( choice == 2 ) // Player decides to buy a potion
{
the_player.gold -= 5; // Subtract the money out of the player
the_player.HamGranade += 1; // Add a potion to the player
Ham_in_stock -= 1; // Subtract a potion out of the store's stockif ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "You just bought my last potion! D:" << endl;
player_is_still_buying = false; // Nothing left to buy!
}
if ( Ham_in_stock == 0 ) // Player bought the last potion
{
cout << "You just bought my last Ham! D:" << endl;
player_is_still_buying = false; // Nothing left to buy!
}
else
cout << "Thank you for your business" << endl;
}
}
}
}
// Player is all done here.
cout << "Goodbye now!" << endl;
system("CLS");
}
};
int main( int, char ** )
{
// Temporary variables to get input from userint g = 99, p = 6, ps = 6,h = 1,hs = 3;
// Self-explanatory:
cout << "Enter starting gold amount:" << endl;
cin >> g;
cout << "Enter starting potions amount:" << endl;
cin >> p;
cout << "Enter number of potions currently in stock (at the store)" << endl;
cin >> ps;
cout << "Enter number of Ham player1 has currently" << endl;
cin >> h;
cout << "Enter number of Ham player1 has currently in stock (at the store)" <<endl;
cin >> hs;
{
player hero( p, g ,h);
store the_store( ps,hs );
// Main game loopbool is_running = true;
while ( is_running ) // will loop forever until "is_running" is false
{
// Display separator, so it is easier to read:
cout << endl << endl;
// Display current player status:
hero.display_status();
// Display available choices:
cout << "There's a store nearby, what must you do?" << endl;
cout << "1) Enter store" << endl;
cout << "2) Make gold" << endl;
cout << "3) Exit game" << endl;
cout << endl;
cout << "Enter choice: " << endl;
// Receive a choice from the user:int choice;
cin >> choice;
if ( choice == 1 ) // Player enters the store
the_store.player_enters( hero );
elseif ( choice == 2 ) // Player creates gold out of thin air
{
cout << "How much gold will you make: " << endl;
int moar_gold;
cin >> moar_gold;
hero.gold += moar_gold;
}
elseif ( choice == 3 )
is_running = false;
}
cout << "Thank you for playing!" << endl;
system("CLS");
}
system("pause");
cin.ignore();
cin.get();
return 0;
}
#include <iostream>usingnamespace std;
// We're going to have an object to represent the player and his/her attributes:class player
{
public:
// The player will have potions and gold variablesint potions;
int gold;
int HamGranade;
// You can also have variables to describe the player's race, class, and name// But for now, we'll keep it simplepublic:
// Here is what's called a "constructor," this is called when the player is created// We want the progammer (aka you) to specify the starting amounts of the player's// gold and potion, thus the "int p" and "int g" parameters
player( int p, int g,int h )
{
// Set potions and gold
potions = p;
gold = g;
HamGranade = h;
// Notify the console:
cout << "Player was created with " << potions << " potions and " << gold << " gold." << endl;
}
// Here is what's called the "destructor," this is called when the player class is destroyed.
~player()
{
cout << "Player was destroyed :.(" << endl;
}
// Here we have a utility function to display the player's current gold and potionsvoid display_status()
{
cout << "You have " << gold << " gold and " << potions << " potions" << endl;
cout << "You have " << HamGranade <<"Ham Granades"<<endl;
}
}//;// Now we're going to create a store class that handles the store operations and other such etcclass store
{
private:
// The members of a store object// Note, this is listed under "private," which means that only the functions below can access this variableint potions_in_stock;
int Ham_in_stock;
public:
// The constructor
store( int num_potions,int num_Ham )
{
// Stock up on potions!
potions_in_stock = num_potions;
Ham_in_stock = num_Ham;
cout << "A store was created with " << potions_in_stock << " potions in stock." << endl;
cout << Ham_in_stock <<"HamGranades"<< endl;
}
// The destructor
~store()
{
cout << "The store was destroyed :.(" << endl;
}
// The player parameter is to specify which player is entering this store// The '&' stands for "reference to" which means that we'll directly be// modifying the player, and not a copy of it. // by changing it to "player the_player" we're going to be working with // a copy of the player that is passed, which isn't what we want, we want// to modify the object itself.void player_enters( player &the_player )
{
// Welcome message
cout << endl;
cout << "Welcome to my store!" << endl;
// Check to see if we have some potions:if ( potions_in_stock == 0 )
{
// We don't
cout << "Unfortunately, I'm out of potions!" << endl;
}
if ( Ham_in_stock == 0 )
{
// We don't
cout << "Unfortunately, I'm out of Ham's!" << endl;
}
elseif ( the_player.gold < 5 ) // (We have potions and then) Check to see if the player has money
{
// He/she doesn't have money
cout << "Unfortunately, you requires more moneys" << endl;
}
else// (The player has money and we have potions)
{
// This is the main loop, which will run forever until this boolean turn false (or the player buys all the potions)bool player_is_still_buying = true;
while ( player_is_still_buying && potions_in_stock > 0 ||player_is_still_buying && Ham_in_stock > 0) // Reads as while the player is still buying and we still have potions
{
// Display player's status:
cout << endl;
the_player.display_status();
if ( the_player.gold < 5 ) // The player is unable to buy any more potions
{
cout << "Looks like you're out of money lol" << endl;
player_is_still_buying = false;
break; // Force out of the "while" loop
}
// Display the menu
cout << endl;
cout << "What would you like to buy?" << endl;
cout << "1) Potion (" << potions_in_stock << ")" << endl;
cout << "2) Ham Granades (" << Ham_in_stock << ")" << endl;
cout << "3) Leave" << endl;
cout << endl;
cout << "Enter choice: ";
// Get a choice from the userint choice;
cin >> choice;
if ( choice == 3 ) // Player decides to leave
player_is_still_buying = false; // When this is set to false, this "while" loop will stop runningelse
{
// Player decides not to leaveif ( choice == 1 ) // Player decides to buy a potion
{
the_player.gold -= 5; // Subtract the money out of the player
the_player.potions += 1; // Add a potion to the player
potions_in_stock -= 1; // Subtract a potion out of the store's stockif ( choice == 2 ) // Player decides to buy a potion
{
the_player.gold -= 5; // Subtract the money out of the player
the_player.HamGranade += 1; // Add a potion to the player
Ham_in_stock -= 1; // Subtract a potion out of the store's stockif ( potions_in_stock == 0 ) // Player bought the last potion
{
cout << "You just bought my last potion! D:" << endl;
player_is_still_buying = false; // Nothing left to buy!
}
if ( Ham_in_stock == 0 ) // Player bought the last potion
{
cout << "You just bought my last Ham! D:" << endl;
player_is_still_buying = false; // Nothing left to buy!
}
else
cout << "Thank you for your business" << endl;
}
}
// (This is the end of the while loop, if all those '}' throw you off)
}
}
// Player is all done here.
cout << "Goodbye now!" << endl;
system("CLS");
}
}
int main( int, char ** )
{
// Temporary variables to get input from userint g = 99, p = 6, ps = 6,h = 1,hs = 3;
// Self-explanatory:
cout << "Enter starting gold amount:" << endl;
cin >> g;
cout << "Enter starting potions amount:" << endl;
cin >> p;
cout << "Enter number of potions currently in stock (at the store)" << endl;
cin >> ps;
cout << "Enter number of Ham player1 has currently" << endl;
cin >> h;
cout << "Enter number of Ham player1 has currently in stock (at the store)" << endl;
cin >> hs;
// This code block here is for demonstration of the constructors and destructors, and isn't necessary
{
player hero( p, g ,h); // Create a player object named "hero" with "p" potions and "g" gold
store the_store( ps,hs ); // Create a store object named "the_store" with "ps" potions in stock// Main game loopbool is_running = true;
while ( is_running ) // will loop forever until "is_running" is false
{
// Display separator, so it is easier to read:
cout << endl << endl;
// Display current player status:
hero.display_status();
// Display available choices:
cout << "There's a store nearby, what must you do?" << endl;
cout << "1) Enter store" << endl;
cout << "2) Make gold" << endl;
cout << "3) Exit game" << endl;
cout << endl;
cout << "Enter choice: " << endl;
// Receive a choice from the user:int choice;
cin >> choice;
if ( choice == 1 ) // Player enters the store
the_store.player_enters( hero );
elseif ( choice == 2 ) // Player creates gold out of thin air
{
cout << "How much gold will you make: " << endl;
int moar_gold;
cin >> moar_gold;
hero.gold += moar_gold;
}
elseif ( choice == 3 ) // Player decides he's had enough :)
is_running = false;
}
cout << "Thank you for playing!" << endl;
system("CLS");
}
system("pause");
cin.ignore();
cin.get();
return 0;
}
}
You are missing some brackets and semicolons - you need to align your brackets better to see this. After adding semicolons after the classes, one missed bracket in your store class, and took out the very last bracket it compiled.