Home / Expert Answers / Computer Science / chapter-3-programming-assignment-outcomes-achieved-input-and-output-mathematical-statements-funct-pa728

(Solved): Chapter 3 programming assignment Outcomes achieved: input and output, mathematical statements, funct ...



Chapter 3 programming assignment Outcomes achieved: input and output, mathematical statements, functions For this assignment, create a C program that calculates average rainfall over a 5 day period: Prompt the user to input 5 rainfall amounts, use scanf to read in the values and store each in its own variable. Then use printf to display five lines with the labels "First day:", "Second day:" etc... each label should be followed by the rainfall amount entered for that day followed by "in." for inches or "mm" if you prefer millimeters and then a newline character. The rainfall values should be aligned in the same column so that the output looks neat. In order to make the scores line up you should use "horizontal tab" escape sequences as necessary. Finally, you should create a separator line using dashes followed by a newline and then display to the user the total rainfall, a newline and the average rainfall. The total and average values should also be aligned with the daily rainfall values in the rows above it. Use appropriate variable data types to allow for decimals such as 0.3. Note: Calculating an average requires an algorithm such as the following: r?+?+3+4+rs this is how we write this mathematically however to write this in C 5.0 r= we need to translate this formula into a line using variable names and appropriate operators on a single line such as the following: avg_rainfall = (rain1 + rain2 + rain3 + rain4 + rain5) / 5.0; The parentheses are important for grouping the five values together before executing the division. An example of what the output might look like is below (user input is in red): Enter 5 daily rainfall amounts: 0.5 0.0 0.2 1.1 0.25 First day: Second day: Third day: Fourth day: Fifth day: 0.5 in. 0.0 in. 0.2 in. 1.1 in. 0.25 in. Total rain: 2.05 in. Average rain: 0.41 in.

student submitted image, transcription available below
Outcomes achieved: input and output, mathematical statements, functions For this assignment, create a program that calculates average rainfall over a 5 day period: Prompt the user to input 5 rainfall amounts, use sconf to read in the values and store each in its own variable. Then use printf to display five lines with the labels "First day:", "Second day:" etc... each label should be followed by the rainfall amount entered for that day followed by "in." for inches or " " if you prefer millimeters and then a newline character. The rainfall values should be aligned in the same column so that the output looks neat. In order to make the scores line up you should use "horizontal tab" escape sequences as necessary. Finally, you should create a separator line using dashes followed by a newline and then display to the user the total rainfall, a newline and the average rainfall. The total and average values should also be aligned with the daily rainfall values in the rows above it. Use appropriate variable data types to allow for decimals such as 0.3 . Note: Calculating an average requires an algorithm such as the following: this is how we write this mathematically however to write this in we need to translate this formula into a line using variable names and appropriate operators on a single line such as the following: The parentheses are important for grouping the five values together before executing the division. An example of what the output might look like is below (user input is in red): Enter 5 daily rainfall amounts: First day: . Second day: in. Third day: . Fourth day: . Fifth day: . Total rain: . Average rain: .


We have an Answer from Expert

View Expert Answer

Expert Answer




We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe