Sunday, March 27, 2011

Mesin Minuman Tin (SWITCH...CASE)



*****************
MESIN TIN MINUMAN
-----------------
1- PEPSI
2- COCA COLA
3- F&N MIRINDA
4- F&N ORANGE
5- 100 PLUS
*****************

Enter your drink:
Enter your money (RM):

Your drink is __________ and your balance are __________

*If the customer does not enter enough money, asked the customer to insert the money. (if...else)



Answer :

#include < iostream.h >
#include < string.h >
#include < conio.h >
#include < stdio.h >

int main()
{

//declare variable
int selection;
float price, money;
char drink[50];

cout<<"\n**********";
cout<<"\nMESIN TIN MINUMAN";
cout<<"\n__________";
cout<<"\n1.PEPSI";
cout<<"\n2.COCA COLA";
cout<<"\n3.F&N MIRINDA";
cout<<"\n4.F&N ORANGE";
cout<<"\n5.100 PLUS";
cout<<"\n**********\n";

cout<<"Enter your drink=";
cin>>selection;
cout<<"Enter you money=";
cin>>money;

//switch...case
switch (selection)
{

case 1: strcpy(drink,"PEPSI");
price=1.70;
break;

case 2: strcpy(drink,"COCA COLA");
price=1.80;
break;

case 3: //drink[50]="F&N MIRINDA";
price=1.50;
break;

case 4: //drink="F&N ORANGE";
price=1.30;
break;

case 5: //drink="100 PLUS";
price=1.60;
break;

default: cout<<"invalid selection";

}

if(money>price)
{
float balance=money-price;
cout<<"your drink is " << drink;
cout<<" and your balance are" << balance;


}
else
{


/*add=price-money;
please add (RM << add << )=
cin>>add_money;
balance=money+add_money;
cout<<"your drink is" << drink << and your balance
are << balance;
*/
}


getch();

return 0;
}



Questions :

No comments:

Post a Comment