//This program calculates the inflation rate given two Consumer Price Index values and prints it to the monitor.
#include <iostream>
usingnamespace std;
/*
* 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
float old_cpi, new_cpi
cout << "Enter the old and new consumer price indicies:";
// TODO #2: Read in two float values for the cpi and store them in the variables
cin >> old_cpi >> new_cpi;
// TODO #3: call the function InflationRate with the two cpis
double InflationRate(old_cpi, new_cpi); //call, add a variable and assign it.
// TODO #4: print the results
cout << "Inflation rate is: ";
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
if(old_cpi<0||new_cpi<0||old_cpi==0)
{
return 0;
}
return (new_cpi - old_cpi) / old_cpi * 100;
// Use (new_cpi - old_cpi) / old_cpi * 100
}
Line 27 doesn't declare a variable and assign the value of the function to it. Combine lines 31 and 27 as cout << "Inflation rate is: " << InflationRate(old_cpi, new_cpi);
//This program calculates the inflation rate given two Consumer Price Index values and prints it to the monitor.
#include <iostream>
usingnamespace std;
/*
* 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
float old_cpi, new_cpi
cout << "Enter the old and new consumer price indicies:";
// TODO #2: Read in two float values for the cpi and store them in the variables
cin >> old_cpi >> new_cpi;
// TODO #3: call the function InflationRate with the two cpis
//call, add a variable and assign it.
// TODO #4: print the results
cout << "Inflation rate is: " << InflationRate(old_cpi, new_cpi);
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
if(old_cpi<0||new_cpi<0||old_cpi==0)
{
return 0;
}
return (new_cpi - old_cpi) / old_cpi * 100;
// Use (new_cpi - old_cpi) / old_cpi * 100
The exact error message is: InflationRate.cpp:21:5: error: expected initializer before 'cout'
cout << "Enter the old and new consumer price indicies:";
^~~~
InflationRate.cpp:24:23: error: 'new_cpi' was not declared in this scope.
cin >> old_cip >> new_cpi;
^~~~~~~
InflationRate.cpp:31:37: error: expected primary expression before 'double'
cout << "Inflation rate is: " << double InflationRate(old_cpi, new_cpi);
^~~~~~~
Look at line 20. Then look at lastchance's post: "You forgot the semi-colon at the end of line 20."
You need to add a semi-colon (;) at the end of line 20.
Learning how to decipher compiler errors is a vital skill in C++. You'll get the hang of it eventually. In general, always look around the lines that it complains about to see if there's anything noticeably wrong within the immediate vicinity (like forgetting a semi-colon).
Thank you but even after adding the semicolon when i try to test it on Mimir all 5 of the cases are marked as Failed..... I seriously don't know where to go from here.