Question: Write an algorithm in a text document for the program. Write a C program called statistics.c that prompts repeatedly for the age of a person

 Write an algorithm in a text document for the program. Write

Write an algorithm in a text document for the program. Write a C program called statistics.c that prompts repeatedly for the age of a person until the user enters -1. Upon entering -1, the program then computes three values shown below and prints them to the screen, excluding the value of -1 from its calculation. The smallest value entered. The largest value entered. The average value from all values entered. The program prints out the values according to the following output format: The smallest entered age is s. The largest entered age is l. The average age is v. The variable s, v, and l needs to be substituted for the corresponding computed values.

My code:

#include

int main(void) {

int age, count =0, sum = 0, smallestNum = 0, largestNum = 0, i =0, j = 0; double avg = 0.00;

do{ printf("Please enter an age: ");

if(scanf("%d", &age) == -1) { printf("Invalid input, exiting"); break; } if(age > largestNum) { largestNum = age; } if(age

avg = sum/count;

printf("The smallest number is: %d and the largest number is: %d", smallestNum, largestNum);

return 0;

}

Write an algorithm in a text document for the program. Write a C program called statistics.c that prompts repeatedly for the age of a person until the user enters -1. Upon entering -1, the program then computes three values shown below and prints them to the screen, excluding the value of -1 from its calculation. The smallest value entered. The largest value entered. The average value from all values entered. The program prints out the values according to the following output format: The smallest entered age is s. The largest entered age is I. The average age is v. The variable s, v, and I needs to be substituted for the corresponding computed values

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!