Question: A typical input sequence might be 5 100 200 300 400 500 Use the below program template to answer each question. The program is created

A typical input sequence might be 5 100 200 300 400 500

Use the below program template to answer each question. The program is created by answering all the questions hence, do not skip any question.

(Housekeeping): Declare the following variables (use meaningful variable names) in your program using appropriate data type. When selecting a data type keep in mind the type of value you want to store, i.e., int, float, character. Also, be sure to use conventional naming standards (meaningful using camel-casing) for all variable declarations.

number

sum

(Hint): Since sum is going to be used for adding the value, it needs to be initialized to zero.

(Display Prompt): Write a printf() statement to ask user for the following message.

Enter the number of values to be processed:

(Input): Add a scanf() statement to store user input for the number of values they wish to process.

(Loop structure): Now, you will write a loop structure to iterate for the number of values you want user to input.

for (int=1; i

{

//code to enter a value and total the values

}

To begin with, your loop structure will look like this

Declare the following variable inside the loop to store the current value. Remember, the scope of this variable is limited to the loop only. It cant be referred or used outside the loop.

value

(Output): Inside the loop, write a display prompt using a printf() statement for user to input a value using the following message.

Enter a value:

(Input): Write a scanf() statement to store the value the user keys in from the keyboard into the variable named value.

(Assignment Statement): Here comes the main part of your program. Now, you need to add this value into the variable sum. So write an assignment statement to add the input value.

sum = sum + value;

(Output): Outside of the loop, write a printf() statement to display the value of sum. Remember, the variable sum is declared outside of the loop so it can be referred/used anywhere within the main function. Also, to display the value stored in a variable you need to include a conversion specifier inside of the quotation marks in the printf() and the variable names within the parentheses.

(Output Screen) When you execute the program, it should be similar to the following:

A typical input sequence might be 5 100 200 300 400 500

GCAWINDOWSlsystem321cmd.exe Enter the number of values to be processed:3 nter a value: 4 Enter a value: 3 Enter a value: 1 Sum of the 3 values is 8 Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!