fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. double calculate_inflation(double, double);
  7. int main()
  8. {
  9. double yearAgo_price;
  10. double currentYear_price;
  11. double inflation_rate; //!!! typo Rate
  12. char again;
  13.  
  14. do{
  15. cout << "Enter the item price one year ago (or zero to quit) : " << endl;
  16. cin >> yearAgo_price;
  17.  
  18. cout << "Enter the item price today: " << endl;
  19. cin >> currentYear_price;
  20.  
  21. cout.setf(ios::fixed); //!!! typo ;
  22. cout.setf(ios::showpoint); //!!! typo iOS
  23. cout.precision(2);
  24.  
  25. inflation_rate=calculate_inflation(yearAgo_price, currentYear_price);
  26. cout << "The inflation rate is " << (inflation_rate*100) << " percent." << endl;
  27.  
  28. cout << "Do you want to continue (Y/N)?" << endl;
  29. cin >> again;
  30.  
  31. }while((again=='Y') || (again=='y')); //!!! == not =
  32.  
  33. return 0;
  34. }
  35.  
  36. double calculate_inflation (double yearAgo_price, double currentYear_price)
  37. {
  38. return ((currentYear_price-yearAgo_price)/ yearAgo_price);
  39. }
Success #stdin #stdout 0s 3416KB
stdin
120 110 y
90 88 y 
2 1 n
stdout
Enter the item price one year ago (or zero to quit) : 
Enter the item price today: 
The inflation rate is -8.33 percent.
Do you want to continue (Y/N)?
Enter the item price one year ago (or zero to quit) : 
Enter the item price today: 
The inflation rate is -2.22 percent.
Do you want to continue (Y/N)?
Enter the item price one year ago (or zero to quit) : 
Enter the item price today: 
The inflation rate is -50.00 percent.
Do you want to continue (Y/N)?