Need to Modify my codes to include a function for both A and B. The function for A should have the quantity of numbers passed in as a parameter and needs to return the largest number. The function for B should have no parameters and return the smallest number. What i have so far is this.
#include <iostream>
using namespace std;
double larger(double x, double y);
int main()
{
char response;
int num = 0;
int newNumber = 0;
int max = -9999;
int min = 9999;
do{
max = -9999;
min = 9999;
cout << "A - Find the largest number with a known quantity of numbers." << endl;
cout << "B - Find the smallest number with an unknown quantity of numbers." << endl;
cout << "C - Quit" << endl;
cin >> response;
switch (response){
case 'a':
case 'A':
cout << "How many numbers do you want to enter?" << endl;
cin >> num;
cout << "Start entering numbers." << endl;
for (int count = 0; count < num; count++){
cin >> newNumber;
if (newNumber > max)
max = newNumber;
}
cout << "The largest number is: " << max << endl;
break;
case 'b':
case 'B':
cout << "Start entering numbers. -99 to quit" << endl;
do{
cin >> newNumber;
if ((newNumber < min) && (newNumber != -99))
min = newNumber;
}while (newNumber != -99);
cout << "The smallest number is: " << min << endl;
break;
}
} while ((response != 'C') && (response != 'c'));
return 0;
}
now the steps i took to write this code was:
1. do{
2. Present Menu
3. Get User Choice
4. Switch statement -> If user choice matches case A, go to 5, if it matches case B, go to 11, if C go to 18
5. Ask how many numbers they want to enter
6. Run for loop. If number of times is less than or equal to user entry, go to step 7, else go to step 10
7. Ask user for input
8. Calculate
9. Go back to 6
10. break to line 17
11. Run while loop
12. Get user entry
13. If user entry is not -99, calculate
14. If user entry is -99, go to line 16
15. Go to step 11
16. break to line 17
17. Loop back to line 1
18. end program
And the next step I need to take steps 6-9 above, create a function for what it is doing and pass the data gathered in step 5 above as a parameter. But honestly lost in exactly how to start the process.... I am not asking for all the answers but some help to get started.