Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // http://pastebin.com/u/TheWhiteFang
- //Tutorial 3 Section A_2
- #include <iostream>
- #include <string>
- using namespace std;
- int main(){
- double price = 0, grandtotal = 0.0;
- float a = 0;
- int b = 0, c = 0;
- int numofitems = 0, totalitems = 0, tempprice = 0;
- string itemname = " ";
- cout << "Enter name of item <enter -1 to exit> : " ;
- getline(cin, itemname);
- while (itemname != "-1"){
- cout << "Enter the price of " << itemname << ": ";
- while (!(cin >> price)){
- cout << "invalid price enter again: ";
- cin.clear();
- cin.ignore(100, '\n');
- }
- cout << "Enter number of " << itemname << " bought :";
- while (!(cin >> numofitems)){
- cout << "invalid number of items... enter again: ";
- cin.clear();
- cin.ignore(100, '\n');
- }
- cout << endl;
- totalitems += numofitems;
- grandtotal += (numofitems*price);
- cout << "Enter name of another item <enter -1 to exit> : ";
- cin >> itemname;
- }
- cout << "\nTotal number of items bought : " << totalitems;
- b = grandtotal;
- c = (grandtotal-b) * 100;
- cout << "\nCost of the items :" << b << " ringgit and " << c << " sen "<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement