QUOTE(chiam dar siang @ Dec 3 2009, 03:23 PM)
» Click to show Spoiler - click again to hide... «
#include<iostream>
#include<iomanip>
using namespace std;
double sum;
int code;
char answer;
double total=0;
double price;
int quantity;
double pay_amount;
string name;
double total1()
{
total = quantity*price;
return total;
}
double sum1()
{
sum = total;
return sum;
}
int main()
{
do
{
cout<<"enter item: ";
cin>>name;
cout<<"enter code: ";
cin>>code;
cout<<"enter quantity: ";
cin>>quantity;
cout<<"enter price: ";
cin>>price;
cout<<"Items"<<setw(10)<<"Code"<<setw(10)<<"Quantity"<<setw(10);
cout<<"Price"<<setw(10)<<"Total"<<endl;
cout<<name<<setw(10)<<code<<setw(10)<<quantity<<setw(10)<<price<<setw(10)<<total1()<<endl;
cout<<"continue?";
cin>>answer;
}
while(answer=='y');
{
cout<<"please pay:"<<sum1()<<endl;
}
system("pause");
return 0;
}
how to get the sum??
am i do wrongly on the declaration part?
» Click to show Spoiler - click again to hide... «
while(answer=='y') {....}
consider using while(answer!='n'), not do{}while; easier to stop the loop and no double looping after stop.
» Click to show Spoiler - click again to hide... «
int main()
{
double sum;
int code;
char answer;
double total=0;
double price;
int quantity;
double pay_amount;
string name;
.....
}
also consider not using global variable, declare all those inside int main()
» Click to show Spoiler - click again to hide... «
cout<<"please pay:"<<sum1()<<endl;
no need open bracket and closed bracket.
» Click to show Spoiler - click again to hide... «
double total1(int quantity, double price)
{
return quantity*price;
}
as for the function
double total1(), you need to pass the data value, on declaration
» Click to show Spoiler - click again to hide... «
double sum1(double sum, double total)
{
sum+=total;
return sum;
}
and as well sum1()
» Click to show Spoiler - click again to hide... «
cout << total1(quantity, price)
to print the total, can use like this