Question: Write a program to read in two consumer price indexes and print out the inflation rate. C++ 1. Start with the student starter code and
Write a program to read in two consumer price indexes and print out the inflation rate. C++
1. Start with the student starter code and follow the instructions in the code.
2. Instructions to complete are tagged in comments like the ones below. They will always begin with // TODO.
// TODO #1: declare two float variables for the old consumer price index (cpi) and the new cpi
// TODO #2: Read in two float values for the cpi and store them in the variables
// TODO #3: call the function InflationRate with the two cpis
// TODO #4: print the results
3. Once you have this program working, submit for credit.
4. Advance to the next lab InflationRate Part2.
MUST USE THE CODE BELOW EXACTLY
//This program calculates the inflation rate given two Consumer Price Index values and prints it to the monitor.
#include
/* * InflationRate - calculates the inflation rate given the old and new consumer price index * @param old_cpi: is the consumer price index that it was a year ago * @param new_cpi: is the consumer price index that it is currently * @returns the computed inflation rate or 0 if inputs are invalid. */ double InflationRate(float old_cpi, float new_cpi);
int main() //C++ programs start by executing the function main { // TODO #1: declare two float variables for the old consumer price index (cpi) and the new cpi
// TODO #2: Read in two float values for the cpi and store them in the variables
// TODO #3: call the function InflationRate with the two cpis
// TODO #4: print the results
return 0; }
// double InflationRate(float old_cpi, float new_cpi) // precondition: both prices must be greater than 0.0 // postcondition: the inflation rate is returned or 0 for invalid inputs double InflationRate(float old_cpi, float new_cpi) { // TODO: Implement InflationRate to calculate the percentage increase or decrease // Use (new_cpi - old_cpi) / old_cpi * 100
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
