CISC2000: Computer Science II LAB 2

InfationRate Part1

This is a 2 part project. The instructions below are for Part 1. Once implemented, submit your solution to InflationRate Part1. If it passes the test cases, move on to InflationRate Part 2. Here is the expected output for InflationRate Part1:

Enter the old and new consumer price indices: 238.170 239.513
Inflation rate is 0.563884

Each lab (InflationRate Part1, 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

 

3. Once you have this program working, submit for credit.

4. Advance to the next lab InflationRate Part2 (next page).

Additional Test Cases

Note: Remember that cin reads the number until it sees a whitespace or non-numeric character. Newline is interpreted the same as space.

 

InflationRate Part2

This lab is Part 2 of a 2 Part Lab called InflationRate. Please complete the instructions. Here is sample output for one run of the program when it's complete. Match the output EXACTLY.

Enter the old and new consumer price indices: 238.343 238.250
Inflation rate is -0.0390204
Try again? (y or Y): y
Enter the old and new consumer price indices: 238.250 237.852
Inflation rate is -0.167049
Try again? (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 with 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 valid inflation rates and the number of computed rates to calculate the average rate. 

4. Print the results after the loop

Additional Test Cases