fork(3) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. const float rub_in_usd = 30.75;
  7. const float rub_in_eur = 38.83;
  8. const float rub_in_rub = 1.0;
  9.  
  10. cout << "Enter sign of target currency\n";
  11. char sign;
  12. cin >> sign;
  13.  
  14. float exchange_index;
  15.  
  16. switch(sign) {
  17. case '$': exchange_index = rub_in_usd; break;
  18. case 'e': exchange_index = rub_in_eur; break;
  19. case 'r': exchange_index = rub_in_rub; break;
  20. }
  21.  
  22. cout << "Enter the amount of money\n";
  23. float money;
  24. cin >> money;
  25.  
  26. cout << "Enter 1 if you want to convert target currency to RUB\n";
  27. cout << "Enter 2 if you want to convert RUB to target currency\n";
  28. int choice;
  29. cin >> choice;
  30. float result;
  31.  
  32. if(choice == 1) {
  33. result = money * exchange_index;
  34. cout << "You will receive " << result << "RUB";
  35. } else if(choice == 2) {
  36. result = money / exchange_index;
  37. cout << "You will receive " << result << sign;
  38. }
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0s 3432KB
stdin
r
500
2
stdout
Enter sign of target currency
Enter the amount of money
Enter 1 if you want to convert target currency to RUB
Enter 2 if you want to convert RUB to target currency
You will receive 500r