Related questions
Add a function to get the CPI values from the user and validate that they are greater than 0.
1. Declare and implement a void function called getCPIValues that takes two float reference parameters for the old_cpi and new_cpi.
2. Move the code that reads in the old_cpi and new_cpi into this function.
3. Add a do-while loop that validates the input, making sure that the old_cpi and new_cpi are valid values.
+ if there is an input error, print "Error: CPI values must be greater than 0." and try to get data again.
4. Replace the code that was moved with a call to this new function.
- Add an array to accumulate the computed inflation rates
1. Declare a constant called MAX_RATES and set it to 20.
2. Declare an array of double values having size MAX_RATES that will be used to accumulate the computed inflation rates.
3. Add code to main that inserts the computed inflation rate into the next position in the array.
4. Be careful to make sure the program does not overflow the array.
- Add a function that sorts the values in an array of doubles.
1. Declare and implement a function called swap_values that takes two double parameters like the one we defined in class. It will be used by the sort_array function to swap inflation rates in the array.
2. Declare and implement a function that uses either a selection sort or bubble sort to put the array values into ascending order (i.e. smallest to largest). In order to sort an array, you must be able to move the values around using swap_values.
+ Function parameters: an array of doubles and an int with the number of elements in the arra
+ Your sort function must use the swap_values function defined above to exchange the values in the array during the sort.
+ You can use either a selection sort or a bubble sort in the sort_array function but it must use the swap_values function.
- Add a function called findMedianRate that calculates the median inflation rate using sort above.
1. Declare and implement a function called findMedianRate that takes two parameters and returns a double which will be the median rate.
+ parameters: an array of doubles and an int with the number of elements in the array (e.g. numRates).
2. Sort the array using your sort_array function defined above. Once the array is sorted, use the following logic to calculate the median value:
+ if the number of rates is odd, then the median rate has as many values preceeding it as following it or in other words, it's the one in the middle.
+ if the number of rates is even, then the median rate is calculated as the average of the two rates in the middle.
Expected Output:
Enter the old and new consumer price indices: Inflation rate is 0.640626
2 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.184142
3 Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0
4 Enter the old and new consumer price indices: Inflation rate is 0.378648
5 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.223225
6 Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0
7 Enter the old and new consumer price indices: Inflation rate is -0.50658
8 Try again? (y or Y): Enter the old and new consumer price indices: Error: CPI values must be greater than 0
9 Enter the old and new consumer price indices: Inflation rate is 0.284456
10 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.489679
11 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.348243
12 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.368315
13 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.0926804
14 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.319909
15 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.190802
16 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.13949
17 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.384759
18 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.14665
19 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.1744
20 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.276358
21 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is 0.195154
22 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.276591
23 Try again? (y or Y): Enter the old and new consumer price indices: Inflation rate is -0.231967
24 Try again? (y or Y): Average rate is 0.0496408
25 Median rate is 0.13354
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- Please see images, C++arrow_forwardYou should not import anything from an external library in the work , The math module has a function, factorialarrow_forwardCan you add a dodamage function to the code? There are options that cause the player to lose lives. We're going to introduce the concept of player health. When the game starts, the player health should be 100. Rather than take an entire life, we want to do damage to the players health and take a life if their health falls below 100. This function should take the players current health as an argument, calculate the new health and return it to the caller. You can choose the amount of damage that is done. *Existing code is below and don't use HTML* const prompt = require("prompt-sync")(); var adventurersName = ["Captain Thomas King","George","Tim","Sarah","Mike","Edward",];var len = 0;var Inventory = new Array(5).fill(" ");Inventory[len++] = "Food";Inventory[len++] = "Wine";Inventory[len++] = "Horses";Inventory[len++] = "Medicine"; var adventurersKilled = 3;var survivors;var numberOfAdventurers = adventurersName.length; survivors = numberOfAdventurers - adventurersKilled;...arrow_forward
- There are 5 mistakes in the code below, highlighted by the red tilde. Fix each mistake by rewriting the code to the right. Just rewrite the lines that are incorrect. Hint, you might have to change a line that doesn’t have a tilde.arrow_forwardJava A jiffy is the scientific name for 1/100th of a secondarrow_forwardC++ Get a value from the user and using a loop, search for the value in the array. Report all the index locations where it is found Report if it is not found anywhere This is part 4 of an ongoing assignment RandArray which consisted of assigning 20 integers with a random value. I am not sure how to write this out so it matches the output ( in the attached pictures ). I have attached the starter code to this problem as well as my code for part 3 which was correct. Thank you ( STARTER CODE ) #include <iostream>using namespace std; #include <cstdlib> // required for rand() int main(){// Put Part3 code here //Part 4// ask cout << "Enter value to find: ";// look through the array. // If it is found:// print // Found 55 at index 12 // if it is not found after looking at all the elements, // print // 0 is not found in randArray } _______________________________________________________________________ ( PART 3 CODE ) #include <iostream> using...arrow_forward
- The following function uses reference variables as parameters. Rewrite the function so it uses pointers instead of reference variables, and then demonstrate the function in a complete program.int doSomething(int &x, int &y){int temp = x;x = y * 10;y = temp * 10;return x + y;}For example: if x = 5, y = 10 then the output should look like the following.arrow_forwardin the C++ version please suppose to have a score corresponding with probabilities at the end and do not use the count[] function. Please explain the detail when coding. DO NOT USE ARRAY. The game of Pig The game of Pig is a dice game with simple rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 ("pig") is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions: roll - if the player rolls 1: the player scores nothing and it becomes the opponents turn. 2 - 6: the number is added to the player's turn total and the player's turn continues. hold - The turn total is added to the player's score and it becomes the opponent's turn. This game is a game of probability. Players can use their knowledge of probabilities to make an educated game decision. Assignment specifications Hold-at-20 means that the player will choose to roll...arrow_forwardNo hand written and fast answer with explanationarrow_forward
- Write in Python Write a function named max that accepts two float values as arguments and returns the value that is the greater of the two. For example, if 7.2 and 12.1 are passed as arguments to the function, the function should return 12.1. Use the function in a program that prompts the user to enter two float values. The program should display the value that is the greater of the two.arrow_forwardPlease tell me where I get wrong.arrow_forwardFix the following function prototype so that the variables are passed by reference, then write the function below. void swap(double x, double y); Hint: be consistent with your style.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education