Here is the code that i have written so far:
CODE
#include <iostream>
using namespace std;
char DoMenu();
void find_largest();
void find_smallest();
int main()
{
char choice;
do
{
choice = DoMenu();
switch (choice)
{
case 'a':
case 'A': find_largest();
break;
case 'b':
case 'B': find_smallest();
break;
}
} while ((choice != 'C') && (choice != 'c'));
return 0;
}
char DoMenu()
{
char MenuChoice;
cout << "\n Menu";
cout << "\n ================";
cout << "\n A - Find the largest # with a known quantity of numbers\n";
cout << "\n B - Find the smallest # with an unknown quantity of numbers\n";
cout << "\n C - Quit\n";
cout << "\n Please enter your choice: ";
cin >> MenuChoice;
return MenuChoice;
}
void find_largest()
{
int largest = -9999;
int numbers=0, input, i=0;
cout << endl;
cout << "How many numbers to enter: ";
cin >> numbers;
for (i=0; i<numbers; i++)
{
cout << "Enter number " << i+1 << ": ";
cin >> input;
if (input > largest)
largest = input;
}
cout << endl;
cout << "The largest number is: " << largest << "\n\n";
}
void find_smallest()
{
int smallest = 9999;
int input=0, i=1;
cout << endl;
do
{
cout << "Enter number " << i << ": ";
cin >> input;
i++;
if ((input < smallest) && (input != -99))
smallest = input;
} while (input != -99);
cout << endl;
cout << "The smallest number is: " << smallest << "\n\n";
}
And I have to do this to it:
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.
Here is some pseudocode for your Greatest function:
CODE
void Greatest()
{
// Initialize final result variable to largest number possible
//
// Ask user How many numbers he would like to enter
// Read number of numbers user plans to enter
// start a loop, increment from 0 to number of numbers user plans to enter
// Read next number
// Compare number to final result variable
// if number is less than final result variable, then
// store in final result variable
// end of loop
}
Can anyone help, i am lost.
Thanks
This post has been edited by jjhaag: 23 Nov, 2007 - 01:15 AM