#include <cctype>
#include <iostream>
using namespace std;
int largest();
void smallest();
char options();
int main()
{
char choice;
do
{
choice = options();
switch (choice)
{
case 'a': largest(); break;
case 'A': largest(); break;
case 'b': smallest(); break;
case 'B': smallest(); break;
}
} while ((choice != 'C') && (choice != 'c'));
return 0;
}
char options()
{
char choice;
cout << endl;
cout << "Enter 'A' to find the largest number with a known quantity of numbers." << endl;
cout << "Enter 'B' to find the smallest number with an unknown quantity of numbers." << endl;
cout << "Enter 'C' to Quit." << endl;
cout << endl;
cout << "Please enter your choice: ";
cout << endl;
cin >> choice;
return choice;
}
int largest()
{
int largest = -9999999;
int numbers = 0, input, C = 0;
cout << endl;
cout << "How many numbers would you like to enter? ";
cin >> numbers;
for (C = 0; C < numbers; C++)
{
cout << "Please Enter Number " << C+1 << ": ";
cin >> input;
if (input > largest)
largest = input;
}
cout << endl;
cout << "The Largest number is " << largest << "." << endl;
return numbers;
}
void smallest()
{
int smallest = 9999999;
int input1 = 0, C1=1;
cout << endl;
cout << "Enter as many numbers as you want." <<endl;
cout << "When you wish to stop entering numbers, enter -99." << endl;
cout << endl;
do
{
cout << "Please enter number " << C1 << ": ";
cin >> input1;
C1++;
if ((input1 < smallest) && (input1 != -99))
smallest = input1;
} while (input1 != -99);
cout << endl;
cout << "The Smallest number is " << smallest << "." << endl;
}
My Teacher says that I need two functions and parameters in "int largest" I thought I did have these but apparently I do not. He also said that I need two return functions? I am lost? any thoughts?
Specific Guilde lines for homework are:
Modify your week 5 assignment 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.
Also:
The code for case 'A' and 'B' now needs to be a function call rather than part of the "main" program. You need to accomplish the following:
1) Start with a working week 5 program
2) Declare the function "largest" at the top of the program. You week 5 program will stay as is till the point that the user once you are in the switch selects A and enters the number he/she wants to enter. At that point you will call largest. Notice that the function that we called "largest" should be declared at the top of the file (your program) but the body of the function is at the end of the file.
3) "The function for B should have no parameters and return the smallest number". Having successfully completed the function for case 'A', this should be a piece of cake. For case 'B' no parameter is passed so the declaration of the function at the top will look like this: int smallest(); Once the user selects B you just make the call to smallest and the code that used to be in main gets executed.
Please note that there is a solution floating on the web that is using functions. That solution will not apply to what we are doing this week because the functions that they created are different than what we expect from you here.
-------------------------------------------------------------------------------
In advance thanks for whatever help you can give me.
This post has been edited by Vision_Dreamer: 30 June 2008 - 07:55 PM

New Topic/Question
Reply




MultiQuote









|