Advertisement
informaticage

Esercizio espressioni C++ Bribro N2

Nov 3rd, 2020
2,072
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main() {
  4.     using namespace std;
  5.  
  6.     double milk_price,
  7.         pasta_price,
  8.         meat_price,
  9.         threshold;
  10.    
  11.     unsigned short milk_amount,
  12.         pasta_amount,
  13.         meat_amount,
  14.         min_discount_percentage,
  15.         max_discount_percentage;
  16.    
  17.     cout << "Insert milk_price, pasta_price, meat_price, threshold: ";
  18.  
  19.     cin >>
  20.         milk_price >>
  21.         pasta_price >>
  22.         meat_price >>
  23.         threshold;
  24.  
  25.     cout << "milk_amount, pasta_amount, meat_amount, min_discount_percentage, max_discount_percentace: ";
  26.  
  27.     cin >>
  28.         milk_amount >>
  29.         pasta_amount >>
  30.         meat_amount >>
  31.         min_discount_percentage >>
  32.         max_discount_percentage;
  33.    
  34.     double
  35.         milk_expence = (double)milk_amount * milk_price,
  36.         pasta_expence = (double)pasta_amount * pasta_price,
  37.         meat_expence = (double)meat_amount * meat_price;
  38.  
  39.     double total_expence =
  40.         milk_expence + pasta_expence + meat_expence;
  41.  
  42.     double discounted;
  43.     if ( total_expence > threshold )
  44.         discounted = total_expence - ( ( max_discount_percentage / (double)100 ) * total_expence );
  45.     else
  46.         discounted = total_expence - ( ( min_discount_percentage / (double)100 ) * total_expence );
  47.  
  48.     cout << "Milk: " << milk_expence << endl
  49.         << "Pasta: " << pasta_expence << endl
  50.         << "Meat: " << meat_expence << endl
  51.         << "Total: " << total_expence << endl
  52.         << "Discounted: " << discounted << endl;
  53.        
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement