Advertisement
TheWhiteFang

Tutorial 3 Section A_1

Nov 9th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip> //std::setprecision
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.  
  9.     float a;
  10.     int b;
  11.    
  12.     float x;
  13.  
  14.     cout << "Enter the price of item: ";
  15.     cin >> a;
  16.  
  17.     if (a > 0){
  18.        
  19.        
  20.         int c = (int)a;
  21.  
  22.         cout << "\nEnter the number of items bought: ";
  23.         cin >> b;
  24.  
  25.         if (b > 0){
  26.            
  27.  
  28.             float d = (a - c)*100;
  29.            
  30.             int y = d;
  31.  
  32.             cout << "\n\nPrice of item is " << c << " ringgit and ";
  33.  
  34.  
  35.             cout << fixed << setprecision(2) << y << " cents "<< endl;
  36.  
  37.             cout << "Number of items bought is " << b << endl;
  38.  
  39.             x = a*b;
  40.  
  41.             cout << "Total amount to be paid is " << x << endl;
  42.         }
  43.        
  44.         else if (b < 0){
  45.            
  46.             cout << "Cmon, buy something...\n";
  47.  
  48.         }
  49.  
  50.         else
  51.         {
  52.             cout << "Enter a valid number geez\n";
  53.         }
  54.     }
  55.  
  56.     else {
  57.         cout << "Enter a valid number geez\n";
  58.     }
  59.  
  60.  
  61.  
  62.     return 0;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement