Advertisement
krasio12356

Cellphones

Apr 16th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6.  
  7. int main()
  8. {
  9.     string s;
  10.     getline(cin, s);
  11.     double budget = stod(s);
  12.     getline(cin, s);
  13.     double count = stod(s);
  14.     string type;
  15.     getline(cin, type);
  16.     double price = 0;
  17.     double discount = 0;
  18.     if (type == "Gsm4e")
  19.     {
  20.         price = 20.5;
  21.         discount = 1;
  22.  
  23.     }
  24.     else if (type == "Mobifon4e")
  25.     {
  26.         price = 50.75;
  27.         discount = 2;
  28.     }
  29.     else if (type == "Telefon4e")
  30.     {
  31.         price = 115;
  32.         discount = 3;
  33.     }
  34.     if (count > 50)
  35.     {
  36.         discount = discount + 7;
  37.        
  38.     }
  39.     else if (count > 20)
  40.     {
  41.         discount = discount + 5;
  42.        
  43.     }
  44.        
  45.     else if (count > 10)
  46.     {
  47.         discount = discount + 2;
  48.        
  49.     }
  50.     else
  51.     {
  52.         discount = discount;
  53.        
  54.     }
  55.     price = price * count;
  56.     price = price - price * discount / 100;
  57.     if (budget >= price)
  58.     {
  59.         printf("The company bought all mobile phones. %.2f leva left.\n", budget - price);
  60.     }
  61.     else
  62.     {
  63.         printf("Not enough money for all mobiles. Company needs %.2f more leva.\n", price - budget);
  64.     }
  65.     return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement