Advertisement
TheWhiteFang

Tutorial 3 Section A_2

Nov 13th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.17 KB | None | 0 0
  1. // http://pastebin.com/u/TheWhiteFang
  2. //Tutorial 3 Section A_2
  3. #include <iostream>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. int main(){
  9.  
  10.     double price = 0, grandtotal = 0.0;
  11.     float a = 0;
  12.     int b = 0, c = 0;
  13.     int numofitems = 0, totalitems = 0, tempprice = 0;
  14.     string itemname = " ";
  15.  
  16.     cout << "Enter name of item <enter -1 to exit> : " ;
  17.     getline(cin, itemname);
  18.  
  19.  
  20.     while (itemname != "-1"){
  21.        
  22.         cout << "Enter the price of " << itemname << ": ";
  23.  
  24.         while (!(cin >> price)){
  25.  
  26.             cout << "invalid price enter again: ";
  27.             cin.clear();
  28.             cin.ignore(100, '\n');
  29.         }
  30.  
  31.         cout << "Enter number of " << itemname << " bought :";
  32.        
  33.         while (!(cin >> numofitems)){
  34.  
  35.             cout << "invalid number of items... enter again: ";
  36.             cin.clear();
  37.             cin.ignore(100, '\n');
  38.         }
  39.         cout << endl;
  40.  
  41.  
  42.         totalitems += numofitems;
  43.         grandtotal += (numofitems*price);
  44.  
  45.         cout << "Enter name of another item <enter -1 to exit> : ";
  46.         cin >> itemname;
  47.    
  48.     }
  49.  
  50.     cout << "\nTotal  number of items bought : " << totalitems;
  51.  
  52.     b = grandtotal;
  53.     c = (grandtotal-b) * 100;
  54.     cout << "\nCost of the items :" << b << " ringgit and " << c << " sen "<<endl;
  55.  
  56.  
  57.  
  58.  
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement