c++ looping dosent work
Nov 20, 2011 at 2:22pm UTC
hai guys!
im new member here.
ive visited this site for past 1 yrs to search for tutorials and tips on c and c++ programming.
its a really good forum.
today im here to seek advise from u guys regarding my assignment.
i wont loop properly.
compare my coding+result and the result that my lecturer wanted.
googled many times, but still fail :( pls help sifus tqvm
my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
#include<iostream>
#include<string>
using namespace std;
class Purchase
{
string name;
int qty;
float price,total;
public :
void set_data(string a, int b, float c);
void calculate();
void print();
};
void Purchase::set_data(string a, int b, float c)
{
name=a;
qty=b;
price=c;
}
void Purchase::calculate()
{
total=(qty * price);
}
void Purchase::print()
{
cout << "========================" << endl;
cout << " RECEIPT " << endl;
cout << "========================" << endl;
cout << "Name : " << name << endl;
cout << "Quantity : " << qty << endl;
cout << "Price : " << price << endl;
cout << "Payment : " << total << endl;
};
int main(void )
{
Purchase p;
string a;
int b;
float c;
string ans;
cout << "Would you like to quit? [Yes/Noo]" << endl;
getline(cin,ans);
while (ans == "N" )
{
cout << "========================" << endl;
cout << " WELCOME " << endl;
cout << "========================" << endl;
cout << "Enter name :" << endl;
getline (cin,a);
cout << "Enter quantity :" << endl;
cin >> b;
cout << "Enter price :" << endl;
cin >> c;
p.set_data(a,b,c);
p.calculate();
p.print();
}
return 0;
}
my result
http://i.imgur.com/v9Gmi.jpg
the result that it should be
http://i.imgur.com/Is28F.jpg
rly hope u guys can help.
thanks in advance
Nov 20, 2011 at 2:31pm UTC
Nov 20, 2011 at 3:11pm UTC
thanks buddy! thats really helps..
my bad im sorry didnt search properly before opening new topic..
is there any way i can close this topic?
Topic archived. No new replies allowed.