May 5, 2012 at 5:44pm UTC
I can't calculate the total amount only for the selected menu..this is my coding..please tell me what i must do..example..here have 4 menu,i only want select 2 menu..how to calculate the total amount for the both total..
#include<iostream>
using namespace std;
void main()
{
int set1,set2,set3,set4,bil,Menu;
double total_amount,total;
cout<<"\t\t\tWelcome";
cout<<"\n\nMenu";
cout<<"\n\nSet 1=RM10.00";
cout<<"\t\t\t\tSet 2=RM20.00";
cout<<"\nSet 3=RM30.00";
cout<<"\t\t\t\tSet 4=RM40.00";
cout<<"\nEnter 0 if finish";
for(bil=1;bil<=4;++bil)
{
cout<<"\n\nSelect menu"<<":Set=";
cin>>Menu;
if(Menu==0)
break;
if(Menu==1)
{
cout<<" Set 1 =RM 10.00";
cout<<"\nHow Many Set =";
cin>>set1;
total=set1*10;
cout<<"\ttotal=RM"<<total;
}
else if(Menu==2)
{
cout<<" Set 2 =RM 20.00";
cout<<"\nHow Many Set =";
cin>>set2;
total=set2*20;
cout<<"\ttotal=RM"<<total;
}
else if(Menu==3)
{
cout<<" Set 3 =RM 30.00";
cout<<"\nHow Many Set =";
cin>>set3;
total=set3*30;
cout<<"\ttotal=RM"<<total;
}
else if(Menu==4)
{
cout<<" Set 4 =RM 40.00";
cout<<"\nHow Many Set =";
cin>>set4;
total=set4*40;
cout<<"\ttotal=RM"<<total;
}
else
cout<<"\nNot in list";
}
total_amount+=total;
cout<<"\nTotal Amount="<<total_amount;
cout<<endl;
}
May 5, 2012 at 5:58pm UTC
initialise the values of total=0.if you don't do so it will store a garbage value and will procede with it....