avr39ripe

cppVasjaTheProgrammerPohorilijEFixedByAVR

Jul 5th, 2021 (edited)
1,281
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     const int paymentFor100Str{ 50 };
  6.     const int stringsToTariff{ 100 };
  7.     const float paymentFor1Str{ paymentFor100Str / (float)stringsToTariff };
  8.     const int fineFor3Lates{ 20 };
  9.     const int minLatesToFine{ 3 };
  10.  
  11.     int wantedSalary{};
  12.     int lates{};
  13.     int codeStrings{};
  14.     int salary{};
  15.  
  16.     int tensNum{};
  17.     //MENU
  18.     char  action{ 'x' };
  19.  
  20.     do
  21.     {
  22.         std::cout << "String amount\t- a\n";
  23.         std::cout << "Lates amount\t- b\n";
  24.         std::cout << "Sallary amount\t- c\n";
  25.         std::cout << "Exit\t\t- x\n";
  26.  
  27.         std::cout << "\nEnter a,b,c to select action or x to exit\n";
  28.  
  29.         std::cin >> action;
  30.  
  31.         switch (action)
  32.         {
  33.         case 'a':
  34.             std::cout << "User selected -  String amount\n";
  35.             //Input
  36.             std::cout << "Enter wanted salary: \n";
  37.             std::cin >> wantedSalary;
  38.             std::cout << "Enter lates number: \n";
  39.             std::cin >> lates;
  40.             //Calculating
  41.             codeStrings = (wantedSalary + lates / minLatesToFine * fineFor3Lates) / paymentFor1Str;
  42.  
  43.             tensNum = codeStrings % stringsToTariff;
  44.             if (tensNum  > 0)
  45.             {
  46.                 codeStrings += stringsToTariff - tensNum;
  47.             }
  48.             //Output
  49.             std::cout << "Vasia should write: " << codeStrings << " code strings\n\n\n";
  50.             break;
  51.  
  52.         case 'b':
  53.             std::cout << "User selected Lates amount\n";
  54.             //Input
  55.             std::cout << "Enter written code strings: \n";
  56.             std::cin >> codeStrings;
  57.             std::cout << "Enter wanted salary: \n";
  58.             std::cin >> wantedSalary;
  59.             //Calculating
  60.             lates = ((codeStrings * paymentFor1Str - wantedSalary) / fineFor3Lates) * minLatesToFine;
  61.             lates += minLatesToFine - 1; // Vasja got 3 - 1 = 2 (as default) lates without fine.
  62.             //Output
  63.             if (lates <= 0)
  64.             {
  65.                 std::cout << "Error Vasia can't late to work!\n";
  66.             }
  67.             else
  68.             {
  69.                 std::cout << "Vasia can have: " << lates << " lates\n\n\n";
  70.             }
  71.             break;
  72.  
  73.         case 'c':
  74.             std::cout << "User selected Sallary amount\n";
  75.             //Input
  76.             std::cout << "Enter written code strings: \n";
  77.             std::cin >> codeStrings;
  78.             std::cout << "Enter lates number: \n";
  79.             std::cin >> lates;
  80.             //Calculating
  81.             salary = codeStrings * paymentFor1Str - lates / 3 * fineFor3Lates;
  82.             //Output
  83.             if (salary <= 0)
  84.             {
  85.                 std::cout << "Vasia wouldn't have any salary\n\n\n";
  86.             }
  87.             else
  88.             {
  89.                 std::cout << "Vasia will have: " << salary << "$\n\n\n";
  90.             }
  91.  
  92.             break;
  93.         case 'x':
  94.             std::cout << "Exiting...\n";
  95.             break;
  96.         default:
  97.             std::cout << "Incorrect menu item! Try again!\n";
  98.         }
  99.     } while (action != 'x');
  100.     return 0;
  101. }
RAW Paste Data