Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

C++ Database Development

Authors: Al Stevens

1st Edition

1558283579, 978-1558283572

More Books

Students also viewed these Databases questions