Jan 21, 2009 at 8:05am UTC
i got a problem with a program that i am doing, i was supposed to create a menu which contains 4 different selection, i got the menu up and running but i couldnt figure out a way to print what is left in the vending machine for each of the drinks and the display sales summary, which display the sales (in $ and cents) for each
of the soft drinks, as well as the total sales.
this is what i have so far..
/*
*/
#include <iostream>
#include <iomanip>
#include <cstring>
#include <fstream>
using namespace std;
char menu1();
void buyDrinks();
void drop();
void listInv();
void listSales();
int main()
{
bool ext = false;
do
{
char action = menu1();
switch (action) //selection frm main menu functions
{
case 'a': buyDrinks();
break;
case 'b': listInv();
break;
case 'c': listSales();
break;
case 4:
break;
case 5:
break;
case 'q':
{
char quit;
cout << "Do you want to quit program (Y/N)?";
cin >> quit;
if(quit == 'Y' || quit == 'y')
{
ext = true;
cout << "GoodBye" << endl;
}
else
{
ext = false;
cout << endl;
}
} break;
default: cout << "Invalid Action." << endl;
}
}while (!ext);
system("pause");
return 0;
}
char menu1()
{
char menu;
cout << "Pls enter your choice of action from" << endl;
cout << "the following functions -" << endl;
cout << "a. Purchase Soft Drinks" << endl;
cout << "b. Display inventory summary" << endl;
cout << "c. Display sales summary" << endl;
cout << "q. Quit" << endl;
cout << "Action #: ";
cin >> menu;
return menu;
}
void buyDrinks()
{
char menu;
bool release = false;
float cost, credit;
cout << "Pls enter your choice of drinks from" << endl;
cout << "the following -" << endl;
cout << "a. Coca-cola " << endl;
cout << "b. Pepsi-cola " << endl;
cout << "c. Sprites " << endl;
cout << "d. Soya Bean " << endl;
cout << "e. Green Tea " << endl;
cout << "f. Orange " << endl;
cout << "q. Quit to main menu" << endl;
cout << "Action #: ";
cin >> menu;
switch (menu) //to display the cost of chosen drink
{
case 'a':
case 'b':
{ cout << "\n\nCost of chosen drink $1.50.";
cost = 1.5;
} break;
case 'c':
{ cout << "\n\nCost of chosen drink $1.20.";
cost = 1.2;
} break;
case 'd':
{ cout << "\n\nCost of chosen drink $1.00.";
cost = 1;
} break;
case 'e':
{ cout << "\n\nCost of chosen drink $0.90.";
cost = 0.9;
} break;
case 'f':
{ cout << "\n\nCost of chosen drink $0.80.";
cost = 0.8;
} break;
case 'q':
{
exit;
} break;
default:
{
cout << "Invalid Action." << endl;
buyDrinks();
}
}
if (menu != 'q')
{
cout << "\nPls insert money.\n";
credit = cost; //assuming customer pays exact amount
if (credit == cost)
release = true;
else
release = false;
if (release)
drop(); //assuming drop() is function for releasing item.
else
{
cout << "\n\nIncorrect amount. Pls select drink again.\n";
buyDrinks();
}
}
}
void drop(){}
void listInv()
{
int
}
void listSales()
{
}
Last edited on Jan 21, 2009 at 8:06am UTC
Jan 21, 2009 at 10:49am UTC
Function buyDrinks
does some calculations, but the values are lost when the function ends. You need make those calculations accessible to other parts of the program.