fork download
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. const double yen_to_euro=0.007215;
  7. const double euro_to_dollar=1.12;
  8. char currency='s';
  9. double x;
  10.  
  11. while(currency!='q')
  12. {
  13. cout << "enter currency and unit(y , e, or d)";
  14.  
  15. while ( (cin >> x >> currency).fail() && !cin.eof()) {
  16. cout << "invalid format";
  17. cin.clear();
  18. }
  19. if (cin.eof())
  20. break;
  21.  
  22. switch(currency){
  23.  
  24. case 'y':
  25. cout <<"euro:"<< x*yen_to_euro<<" dollar:"<<x*yen_to_euro*euro_to_dollar<<'\n';
  26. break;
  27. case 'e':
  28. cout <<"yen:"<< (x*(1.0/yen_to_euro))<<" dollar:"<<(x*euro_to_dollar)<<'\n';
  29. break;
  30. case 'd':
  31. cout <<" yen:"<< x*(1.0/yen_to_euro)*(1.0/euro_to_dollar)<<" euro:"<<x*(1.0/euro_to_dollar)<<'\n';
  32. break;
  33. case 'q':
  34. currency='q';
  35. break;
  36. default:
  37. cout << "invalid";
  38. break;
  39.  
  40. }
  41.  
  42. }
  43.  
  44.  
  45. }
Success #stdin #stdout 0s 3460KB
stdin
12 e
12e
12 y
stdout
enter currency and unit(y , e, or d)yen:1663.2 dollar:13.44
enter currency and unit(y , e, or d)invalid formateuro:0.08658 dollar:0.0969696
enter currency and unit(y , e, or d)