For this c++ hw part 2 needs to be completed and match with the output displayed for part 2 My code: //This program calculates the inflation rate given two Consumer Price Index values and prints it to the monitor. #include using namespace 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 oldCPI; float newCPI; float iRate; // TODO #2: Read in two float values for the cpi and store them in the variables cout << "Enter the old and new consumer price indices: \n"; cin >> oldCPI >> newCPI; // TODO #3: call the function InflationRate with the two cpis iRate = InflationRate(oldCPI, newCPI); // TODO #4: print the results cout << "Inflation rate is " << iRate << endl; // BONUS #1: Put the logic in TODO #2-4 in a loop that asks the user to enter 'y' if there's more data // BONUS #2: Keep a running total of the valid inflation rates and the number of computed rates to calculate the average rate. // Print the results after the loop return 0; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

For this c++ hw part 2 needs to be completed and match with the output displayed for part 2

My code:

//This program calculates the inflation rate given two Consumer Price Index values and prints it to the monitor.

#include <iostream>
using namespace 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 oldCPI;
float newCPI;
float iRate;

// TODO #2: Read in two float values for the cpi and store them in the variables

cout << "Enter the old and new consumer price indices: \n";
cin >> oldCPI >> newCPI;

// TODO #3: call the function InflationRate with the two cpis

iRate = InflationRate(oldCPI, newCPI);

// TODO #4: print the results

cout << "Inflation rate is " << iRate << endl;

// BONUS #1: Put the logic in TODO #2-4 in a loop that asks the user to enter 'y' if there's more data


// BONUS #2: Keep a running total of the valid inflation rates and the number of computed rates to calculate the average rate.
// Print the results after the loop

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

double results;

if(old_cpi > 0 && new_cpi > 0)
{
results = (new_cpi - old_cpi) / old_cpi * 100;
return results;
}

else
return 0;
}

DESCRIPTION
Match the output EXACTLY.
Enter the old and new consumer price Indices: 238.343 238.250
Inflation rate is -0.0390204
Try agaln? (y or Y): y
Enter the old and new consumer price Indices: 238.250 237.852
Inflation rate is -0.167049
Try agaln? (y or Y): n
Average rate Is -0.103035
Part 2
1. Here are the original instructions from Part 1.
// 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 vwith the two cpis
// TODO #4: print the results
2. Put the logic in TODO #2-4 into a loop that asks the user to enter 'y (or Y) if there's more data to be entered.
3. Keep a running total of the valld inflation rates and the number of computed rates to calculate the average
rate.
4. Print the results after the loop
Transcribed Image Text:DESCRIPTION Match the output EXACTLY. Enter the old and new consumer price Indices: 238.343 238.250 Inflation rate is -0.0390204 Try agaln? (y or Y): y Enter the old and new consumer price Indices: 238.250 237.852 Inflation rate is -0.167049 Try agaln? (y or Y): n Average rate Is -0.103035 Part 2 1. Here are the original instructions from Part 1. // 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 vwith the two cpis // TODO #4: print the results 2. Put the logic in TODO #2-4 into a loop that asks the user to enter 'y (or Y) if there's more data to be entered. 3. Keep a running total of the valld inflation rates and the number of computed rates to calculate the average rate. 4. Print the results after the loop
Enter the old and new consumer price Indices: 238.170 239.513
Inflation rate Is 0.563884
Each lab (InflationRate Partl, InflationRate Part2 and InflationRate Part3) will build successively on the previous
submission.
Part 1
Write a program to read in two consumer price indexes and print out the inflation rate.
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<br>
// TODO #3: call the function InflationRate with the two cpis
// TODO #4: print the results
Transcribed Image Text:Enter the old and new consumer price Indices: 238.170 239.513 Inflation rate Is 0.563884 Each lab (InflationRate Partl, InflationRate Part2 and InflationRate Part3) will build successively on the previous submission. Part 1 Write a program to read in two consumer price indexes and print out the inflation rate. 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<br> // TODO #3: call the function InflationRate with the two cpis // TODO #4: print the results
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 6 steps with 4 images

Blurred answer
Knowledge Booster
Algebraic Expressions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education