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 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 < smallestNum) { smallestNum = age; } sum = age+= age; printf("%d", sum); count++; // counting the number of numbers entered for future calculation of the average*/ }while(age != -1);
avg = sum/count;
printf("The smallest number is: %d and the largest number is: %d", smallestNum, largestNum);
return 0;
}
It is not working, I need to compute the average and smallest number. largest number works. Please change as little possible
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started