Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C language (array, functions, decisions) ( ..) Write a program to get a gas stations name and 4 gasoline prices, calculate and display the average

C language (array, functions, decisions) (..)

Write a program to get a gas stations name and 4 gasoline prices, calculate and display the average of the prices, and determine and display if the price of gas is rising or not. Top-Level Instructions: ? Get the gas station name, and store the name in a variable. ? Using a loop, get 4 gas prices, validating that each price is between $0.01 and $5.00 (and continue to re-get the price if it is not in the range), and store the 4 prices in an array. ? Using a function, calculate and return the average of the 4 gas prices. Pass to the function the 4 gas prices. Store the return value from the function in a variable. ? Display the stations name and average gas price. ? Using a function, determine and return whether the price of gas is rising or not. Pass to the function the 1st gas price and the average of the 4 gas prices. ? Display whether the price of gas is rising or not. Detailed Instructions: 1. Create a local constant for the size of the array that will hold the 4 gas prices 2. Create 2 local constants for the minimum ($0.01) and maximum ($5.00) gas prices used when validating the gas prices entered by the user 3. Create a local character array (of size 30) to hold the gas stations name 4. Create a local array to hold the stations 4 gas prices 5. Create any other local variables needed for the program 6. Prompt the user for the gas stations name, use fgets() to get the name (which could include spaces), store the name in the character array, and strip-off the at the end of the string 7. Create a loop that runs 4 times to get the stations 4 gas prices a. Prompt for the stations gas price, and get the price b. Using the constants, validate that the price is between $0.01 and $5.00 (inclusive), and if not re-get the price until the price is in the correct range (use the constants for both the validation condition and the error message) (Note the indenting of the message and the re-prompt in Example Run #2) c. Store the price in the array 8. Display a blank line between the inputs and the outputs 9. Pass 4 pieces of data - the 4 individual gas prices in the array - to a function, calculate the average of the gas prices, return the average, and store the average in a variable (if you want, instead of passing the 4 individual gas prices, you can pass the entire array and its size to the function) (create local variables in the function as needed) (dont forget to create the function prototype if necessary) Final Project 10. In the main program, display the gas stations name and average price of the gas 11. Pass the 1st gas price and the average to a Boolean function named IsRising(), and determine if the price of gas is rising or not (create local variables in the function as needed) (do not display anything in the function have the function return true if the price of gas is rising, or false if the price of gas is falling) (dont forget to create the function prototype if necessary) 12. Using the return value of the Boolean function, determine and display in the main program whether the price of gas is rising or falling 13. Display a blank line before Press any key to continue Example Run #1: Enter the gas stations name: Geo Gas Enter Geo Gass gas price #1: $1.95 Enter Geo Gass gas price #2: $1.97 Enter Geo Gass gas price #3: $2.05 Enter Geo Gass gas price #4: $2.09 Geo Gas had an average gas price of $2.01. The price of gas at Geo Gas is rising. Example Run #2: Enter the gas stations name: Fossil Fuel Enter Fossil Fuels gas price #1: $2.59 Enter Fossil Fuels gas price #2: $12.49 The price was not in the range of $0.01 - $5.00. Please re-enter gas price #2: $2.49 Enter Fossil Fuels gas price #3: $2.39 Enter Fossil Fuels gas price #4: $2.35 Fossil Fuel had an average gas price of $2.46. The price of gas at Fossil Fuel is falling. The example runs show EXACTLY how your program input and output will look.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Understanding Databases Concepts And Practice

Authors: Suzanne W Dietrich

1st Edition

1119827949, 9781119827948

More Books

Students also viewed these Databases questions