Question
C programming. Almost finished with my project, but I'm not sure how to get the numbers to stop rounding. (ex. if i need 36.97 the
C programming. Almost finished with my project, but I'm not sure how to get the numbers to stop rounding. (ex. if i need 36.97 the program will spit out 36.00). Thank you in advance
#include
int main() {
int age; int count = 0; int sum =0; int smallAge = 0; int largeAge = 0; double avg = 0.00; do { printf("Please enter an age (0-120), enter -1 to finish: "); scanf("%d", &age); //printf("%d ", age); if (age == -1) { //printf("Invalid input, exiting "); break; }
if(count==0){ smallAge = age; largeAge = age; } if (age > largeAge) { largeAge = age; } if (age < smallAge) { smallAge = age; } if (age <= 120 && age >= 0) { sum += age; count++; } //sum += age; // count++; } while (age != -1);
//avg =(double) sum / count; avg = sum / count;
//printf(" "); printf("The smallest entered age is %d. ",smallAge); printf("The largest entered age is %d. ",largeAge); printf("The average age is %.2lf. ",avg);
return 0; }
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