Monday, March 28, 2011

Programming Exercise Switch...Case...


#include < iostream.h >
main()
{

//declair variable
int selection, quantity;
double price;

cout<<"Muhammad FIrdaus Bin Hasmi" << endl;
cout<<"05-201006-00003" << endl;

cout<<"\n1.Pen = RM 0.50";
cout<<"\n2.Pensil = RM 0.30";
cout<<"\n3.Ruler = RM 0.20";
cout<<"\n4.Erser = RM 0.10";

cout<<"\n\nEnter your selection = ";
cin>>selection;
cout<<"\nEnter your quantity = ";
cin>>quantity;

switch (selection)
{
case 1 : price = quantity * 0.50;
cout<<"\nPrice = RM " << price;
cout<<"\n\nYour selection is Pen with" << quantity;
cout<<"As your quantity(s)" << endl;
break;

case 2 : price = quantity * 0.30;
cout<<"\nPrice = RM " << price \n;
cout<<"\nYour selection is Pensil with" << quantity;
cout<<"As your quantity(s)" << endl;
break;

case 3 : price = quantity * 0.20;
cout<<"\nPrice = RM " << price << endl;
cout<<"\nYour selection is Ruler with " << quantity;
cout<<"As your quantity(s)" << endl;
break;

case 4 : price = quantity * 0.10;
cout<<"\nPrice = RM " << price << endl;
cout<<"\nYour selection is Erser with " << quantity;
cout<<"As your quantity(s)" << endl;
break;

default : cout<<"\nInvalid selection" << endl;
}

return 0;
}

No comments:

Post a Comment