donmike25

tuto 3_1

Nov 13th, 2014
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 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 price;
  10.             int item;
  11.             int temp;
  12.             float total;
  13.      
  14.             cout << "Enter the price of item: ";
  15.             cin >> price;
  16.      
  17.             if (price > 0){
  18.                    
  19.                    
  20.                     temp = price;
  21.      
  22.                     cout << "\nEnter the number of items bought: ";
  23.                     cin >> item;
  24.      
  25.                     if (item > 0){
  26.                            
  27.      
  28.                             float total = price - temp;
  29.                             cout << "\n\nPrice of item is " << temp << " and ";
  30.      
  31.      
  32.                             cout << fixed << setprecision(2) << total << endl;
  33.      
  34.                             cout << "Number of items bought is " << item << endl;
  35.      
  36.                             total = price*item;
  37.      
  38.                             cout << "Total amount to be paid is " << total << endl;
  39.                     }
  40.                    
  41.                     else if (item < 0){
  42.                            
  43.                             cout << "Buy something dude \n";
  44.      
  45.                     }
  46.      
  47.                     else
  48.                     {
  49.                             cout << "Enter a valid number \n";
  50.                     }
  51.             }
  52.      
  53.             else {
  54.                     cout << "Enter a valid number \n";
  55.             }
  56.      
  57.      
  58.      
  59.             return 0;
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment