Need Assistance with Simple Program

I'm having trouble figuring out how to finish this assignment. Basically, the program prompts user for first name and then outputs a menu for them to "purchase" from, user enters quantity of the product they want and totals are calculated. The items only have a limited stock and if the user tries to buy more than what is in stock, an error message is output appropriately. I am trying to figure out how to alter the menu to readout "ITEM NO LONGER AVAILABLE" after the item has been sold out.


/*

// User Input
cout<<"Please enter your first name only: ";
cin>>name1;

cout<<"Hello "<<name1<<" thank you for shopping Lisa supplements."<<endl;
cout<<"Inventory is listed below, note some items are limited:"<<endl;


// Menu Output
do
{
cout<<" Roots n' Stuff "<<endl
<<"-------------------------"<<endl
<<"1. Ginko Root($4.50)"<<endl
<<"2. Mandrake Root($1.23)"<<endl
<<"3. Ginseng Root($2.39)"<<endl
<<"4. Square Root($99.98)"<<endl
<<"5. VitaminR Root($0.78)"<<endl
<<"6. Quit "<<endl;

cout<<"Please enter the number that corresponds to your choice ";
cin>>choice;

// Calculations for purchase total
subtotal = (gin_total + man_total
+ ginse_total + sq_total + r_total);

total_post_tax = ((subtotal * TAX) + subtotal);

// Menu Options
switch(choice)
{
case 1:
cout<<USERPROMPT<<endl;
cin>>gin_quantity;

if (gin_quantity <= GIN_STOCK)
{
gin_total = (gin_quantity * GIN_COST);
}
else if (gin_quantity > GIN_STOCK)
{
cout<<"Sorry, we only have "<<GIN_STOCK<<" of those."<<endl
<<QUANTITYMAX<<GIN_STOCK<<" ginko roots."<<endl;

gin_total = (GIN_STOCK * GIN_COST);
}
break;
*/

Everything I have thus far compiles and runs as intended. I apologize for the spacing, the copy and paste skewed it.

Here is my menu and one of the cases dictating a menu choice. The format basically follows for the next 4 cases and then a 6th case representing quit and totaling the user's purchase. As I said, I'm interested in adding "item no longer available" alongside the appropriate menu output when the else statement is executed.
Hi,

firstly please post your whole code and also use code tags
http://www.cplusplus.com/articles/jEywvCM9/

1
2
3
4
else if (gin_quantity > GIN_STOCK)
{ 
cout<<"Sorry, we only have "<<GIN_STOCK<<" of those."<<endl
<<QUANTITYMAX<<GIN_STOCK<<" ginko roots."<<endl;


you may edit this part of your code to get the desired output
Hello cimps1987,

I had to guess at some of this, but to alter the output of the menu you could do this:
1
2
3
4
5
6
7
8
9
10
11
12
cout << " Roots n' Stuff " << endl
       << "-------------------------" << endl;
if (GIN_STOCK > 0)
    cout  << setw(17) << left << "1. Ginko Root" << right << setw(8) << "($4.50)" << setw(6) << GIN_STOCK << " in stock" << endl;
else
    cout << setw(17) << left << "1. Ginko Root" << right << setw(8) << "($4.50)" << setw(6) << GIN_STOCK << " in stock ITEM NO LONGER AVAILABLE" << endl;

cout << setw(17) << left << "2. Mandrake Root" << right << setw(8) << "($1.23)" << setw(6) << MR_STOCK << " in stock" << endl
<< setw(17) << left << "3. Ginseng Root" << right << setw(8) << "($2.39)" << endl
<< setw(17) << left << "4. Square Root" << right << setw(8) << "($99.98)" << endl
<< setw(17) << left << "5. VitaminR Root" << right << setw(8) << "($0.78)" << endl
<< setw(17) << left << "6. Quit " << endl;

you can ignore the setw, left and right if you want. I did that just to format the output. If you keep the formatting include iomanip header file.

Hope that helps,

Andy


Topic archived. No new replies allowed.