sting array input
Oct 3, 2008 at 6:30am UTC
This is a vending machine project. The vendor can input/change items and price... I'm stuck on how to make my VendingItem an "variable" type, and I may declare an int type to hold the price, but how can i make the price pointing to the right item? (Suppose I will input 5 items) Here is my code, it's not much.... Thanks~!
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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
//class vendor, vendor control, change items
class vendor
{
public :
int VendorArraySize;
string VendingItem[];
char Choice;
void call_user_interface()
{
cout << "Would you like to change the price or items? \n"
<< "For Item Enter I or i \n"
<< "For Price Enter P or p \n" ;
cin >> Choice;
//Item add/change
if (Choice == 'I' || Choice == 'i' )
{
cout << "Please enter how many items you want to put in:(1-5) " << endl;
for (int E = 1; E < 2; E++)
{
cin >> VendorArraySize;
}
cout << "Please enter the item(s) that you wish to sell : " << endl;
for (int E = 0; E <= VendorArraySize; E++)
{
getline(cin, VendingItem[]);
}
}
cout << "You've Enter the following Items : " << endl;
for ( int i = 0; i <= VendorArraySize; i++)
{
cout << i+1 << " " << VendingItem << endl;
}
//Price change
if (Choice == 'P' || Choice == 'p' )
{
}
}
};
//class customer, selling function
class customer
{
public :
int itemNumber, totalCost;
double amount, change;
char Choice;
void call_user_interface()
{
cout << "Items that entered from vendor() and price: Hello $ 3.90 ...." << endl;
cout << "Please Enter The Amount You Wish To Spend: $" << amount << endl;
cin >> amount;
cout << "Please select your item!" << endl;
cin >> itemNumber;
/*if(amount < " *ITEM'S PRICE* ")
{
cout << "Not enough money, please reenter the amount!" << endl;
}
else
{
cout << "Here is your " << " *SELECTED ITEM* " << "!" << endl;
change = amount - " *ItemPrice* ";
cout << "And your change is: $" << change << endl;
}*/
}
};
//start up
class mainPrompt
{
customer myCustomer;
vendor myVendor;
public :
void call_user_interface()
{
char Choice;
do
{
cout <<"Please Enter Your Choice: \n"
<<"-V- as vendor control \n"
<<"-S- as ready to sell \n"
<<"-Q- to quit the program \n" ;
cin >> Choice;
if (Choice == 'V' || Choice == 'v' )
myVendor.call_user_interface();
if (Choice == 'S' || Choice == 's' )
myCustomer.call_user_interface();
}while (Choice != 'Q' && Choice != 'q' );
}
};
//main
int main()
{
mainPrompt Prompt;
Prompt.call_user_interface();
return 0;
}
Last edited on Oct 3, 2008 at 6:31am UTC
Topic archived. No new replies allowed.