write a program that outputs inflation rates for two successive years and whethe
ID: 3530487 • Letter: W
Question
write a program that outputs inflation rates for two successive years and whether the inflation is increasing or decreasing.Ask the user to input the current price of an item and its price one year and two years ago.To calculate the inflation rate for a year,subtract the price of the item for that year from the price of the item one year ago and then divide the result by the price a year ago.Your program must contain at least the following functions : a function to get the input(getPrices) , a function to calculate the results (calculateInflation), and a function to output the results(printResults). Use appropriate parameters to pass the information in and out of the function.Do not use any global variables.Explanation / Answer
This is a corrected code..This calculate the inflation rate for both the years successively...So please rate my both posts..1st one and this one..Please consider my effort.
The code starts form here :
#include<iostream.h>
#include<conio.h>
int getPrices();
double calculateInflation(int,int);
void printResults(double);
int main()
{
int currentPrice=0;
int>
int twoYearBackPrice=0;
double Inflation=0;
cout <<"Please Enter the current price of the year"<<endl;
currentPrice=getPrices();
cout<<"Please Enter the price of Item one year ago"<<endl;
oneYearBackPrice = getPrices();
cout <<"Please Enter the price of Item two Year Back"<<endl;
twoYearBackPrice = getPrices();
cout<<"inflation Rate for curremt year with respect to previous year is : "<<endl;
Inflation=calculateInflation(currentPrice,oneYearBackPrice);
printResults(Inflation);
cout<<"inflation Rate for previous year with respect to two year back price is : "<<endl;
Inflation=calculateInflation(oneYearBackPrice,twoYearBackPrice);
printResults(Inflation);
return 0;
}
int getPrices()
{
int inputvalue=0;
cin >> inputvalue;
return inputvalue;
}
void printResults(double inflation)
{
if(inflation == 0)
{
cout << "The price of the Item has not been changed so the inflation for the Item is : "<<inflation<<endl;
}
else
{
cout << "The inflation for the item is :"<<inflation<<endl;
}
}
double calculateInflation(int currentPrice,int oneYearBackPrice)
{
int priceDiffer = currentPrice - oneYearBackPrice;
double inflation =(float) priceDiffer /(float)oneYearBackPrice;
return inflation;
}
Sample output :
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.