Write a program in C that outputs inflation rates for two su

Write a program in C++ that outputs inflation rates for two successive years and whether the inflation s increasing or decreasing. Ask the user to input current price of the item and its price one and two years ago.

Solution

#include <iostream>

using namespace std;

double calculate_inflation(double, double);
int main()
{
double yearAgo_price;
double currentYear_price;
double inflation_rate;


cout << \"Enter the item price one year ago (or zero to quit) : \" << endl;
cin >> yearAgo_price;

cout << \"Enter the item price today: \" << endl;
cin >> currentYear_price;


inflation_rate=calculate_inflation(yearAgo_price, currentYear_price);
cout << \"The inflation rate is \" << (inflation_rate*100) << \" percent.\" << endl;

if(inflation_rate>0) {
cout << \"increasing inflation rate\";
}
else if(inflation_rate<0){
cout << \"decereasing inflation rate\";
}
else{
cout<<\"NO change\";
}


return 0;
}

double calculate_inflation (double yearAgo_price, double currentYear_price)
{
return ((currentYear_price-yearAgo_price)/ yearAgo_price);
}

Write a program in C++ that outputs inflation rates for two successive years and whether the inflation s increasing or decreasing. Ask the user to input current

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site