i am having trouble with functions
write a program that outputs inflation rates for two successive years and determines whether the inflation is increasing or decreasing.
Ask the user to input the current price of an item (currPrice), its price one year ago (oneYearPrice) and two years ago (twoYearPrice).
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.
For example, the current inflation (currInf) would be oneYearPrice subtracted from currPrice and then divided by oneYearPrice. Similarly, last years inflation (prevInf) would be twoYearPrice subtracted from oneYearPrice and than divided by twoYearPrice.
Your program must contain at least the following functions: a function to calculate the results, and a functions to output the results. Use appropriate parameters (function arguments) to pass the information in and out of the functions. (Do not use global variables).
The point of the exercise is to learn more about information passing between functions. Notice that the point assignment for this exercise is purely on function declaration and data exchange among functions.
I have some hints for you:
Your input is the price of an item (let's say the price of a gallon of gas) for the last three years. For example, user will enter the current price of a gallon of regular gas today (currentyear), last year today (lastyear), and two years ago today(twoyearsago).
Once you collect all the input you need in the main() function, you will need to compute the inflation.
Notice that, you will need to compute inflation twice. Inflation from last year to today, and inflation from two years ago to last year. I would write a function called (computeInflation()) that takes two prices of an item as input and computes and returns the inflation. I would need to call computeInflation() function twice, for the first call I send current year and the last year price as input and get last years inflation. The second call I would send the lat year's and two year ago price as input and get the inflation of two years ago. At this point you have two inflation rates in the main() function.
You should have a second function that prints out a nice output. You will need to send the two inflation rates you computed as input. The function would output the inflation rates and also tell us if inflation is on the rise or declining.
need some guidance in fixing up my code.
using namespace std;
int computeInflation(int oneYearPrice, int twoYearPrice);
double computeInflation(double oneYearPrice, double twoYearPrice);
double computeInflation(double oneYearPrice, int twoYearPrice);
double computeInflation(int oneYearPrice, double twoYearPrice);
if ( currInf > prevInf )
cout << "The inflation rate is increasing" << endl;
else if (currInf < prevInf)
cout << "The inflation rate is decreasing" << endl;
cout << "There is no change in the inflation rate" << endl;
cout << "what is the current price" << endl;
cin >> currPrice;
cout << "what is the price of one year ago" << endl;
cin >> oneYearPrice;
cout << "what is the price of two years ago" << endl;
cin >> twoYearPrice;
currInf = (currPrice-oneYearPrice) / (oneYearPrice);
currInf = (currPrice-twoYearPrice) / (twoYearPrice);
cout << "your total tax is $" << currInf << " per month" << endl;