Write a program that asks a doctor to enter the number of patients that walked into his/her clinic at the end of the day.
(On different days, the clinic may get different numbers of patients.) Then the program should ask the doctor
to enter each patient’s age and store it in a dynamically allocated array.
Once the doctor has finished entering all the ages,
the program should display all the ages in one line, separated by commas (see the screenshot).
The program should also display the average age, highest and
lowest ages among all of the patients.
(You should free the dynamically allocated memory at the right location).
At the end of the program, it should ask the doctor if he/she wants to continue.
You need to ask for the number of patients before using that value to allocate the array. It's best to create functions to calculate the average, min and max. Assuming they've been implemented, main looks like:
My array has integer values, but the average will be a double.
1 2 3 4 5 6
double average(int* patientAge, int numPatients) {
double sum = 0;
for (int count = 0; count < numPatients; ++count)
sum += patientAge[count];
return sum / patientAge;
}
So you were right, you need a loop. There should be plenty of examples of min/max functions around. The C++ Standard Template Library also has an implementation, but I guess you'll be expected to write your own.