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
|
#include <iostream>
#include <iomanip>
#include <cctype>
#include <string>
using namespace std;
const int items = 5;
const string ShopInventory[items] = {"Helms", "Boots", "Swords", "Axes", "Leather Armors"};
const int ItemPrices[items]= {10, 5, 20, 30, 50};
void PrintShop();
string PlayerInput(string [], int&);
int main()
{
string PlayerInventory[items];
int playerMoney = 100;
char Response;
cout << "\t\tWelcome traveler to my lovely shop. \n";
cout << "\nFeel free to browse many of the wonderful items within";
cout << " this store. " << endl;
PrintShop();
while(toupper(Response) != 'N')
{
cout << PlayerInput(PlayerInventory, playerMoney);
cout << "\nIs there anything else that you would like to buy? " << endl;
cout << "\nEnter n or N to quit. Else enter y or Y ";
cin >> Response;
while(toupper(Response) != 'Y' && toupper(Response) != 'N')
{
cerr << "\nSorry, wrong input. Please try again. ";
cin >> Response;
}
}
return 0;
}
void PrintShop()
{
cout << endl;
cout << " ***** Shop Inventory ***** " << endl << endl;
cout << "Shop items " << "\t\tPrice Per Item. " << endl << endl;
for(int i=0; i<items; i++)
{
cout << i+1 << ".) " << left << setw(22) << ShopInventory[i];
cout << left << setw(3) << ItemPrices[i] << " Gold" << endl;
}
}
string PlayerInput(string PlayerInventory[], int &playerMoney)
{
string Input;
cout << "\nEnter what you would like to buy. ";
getline(cin ,Input, '\n');
for(int i=0; i<items; i++)
{
while(Input != ShopInventory[i])
{
cout << "\nThe item that you enter isn't in my inventory. ";
cin >> Input;
}
}
}
|