donmike25 icon

tuto 3_1

donmike25 | PRO | 11/13/14 09:30:37 AM UTC | 0 ⭐ | 283 👁️ | Never ⏰ | []
C++ |

1.57 KB

|

None

|

0 👍

/

0 👎

 #include <iostream>
    #include <iomanip> //std::setprecision
     
    using namespace std;
     
    int main()
    {
     
            float price;
            int item;
            int temp;
            float total;
     
            cout << "Enter the price of item: ";
            cin >> price;
     
            if (price > 0){
                   
                   
                    temp = price;
     
                    cout << "\nEnter the number of items bought: ";
                    cin >> item;
     
                    if (item > 0){
                           
     
                            float total = price - temp;
                            cout << "\n\nPrice of item is " << temp << " and ";
     
     
                            cout << fixed << setprecision(2) << total << endl;
     
                            cout << "Number of items bought is " << item << endl;
     
                            total = price*item;
     
                            cout << "Total amount to be paid is " << total << endl;
                    }
                   
                    else if (item < 0){
                           
                            cout << "Buy something dude \n";
     
                    }
     
                    else
                    {
                            cout << "Enter a valid number \n";
                    }
            }
     
            else {
                    cout << "Enter a valid number \n";
            }
     
     
     
            return 0;
    }

Comments