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.
Here is some pseudocode for your Greatest function:
int Greatest(int count)
{
// Initialize final result variable to largest number possible
//
// start a loop, increment from 0 to count
// Read next number
// Compare number to final result variable
// if number is greater than final result variable, then
// store in final result variable
// end of loop
// return final result
}// end of function greatest
This is what i was the information i was givin to change my code.. but i don't understand what exactly i am suppose to be doing...
this is my code so far..(before changes)
#include <iostream>
using namespace std;
const int SENTINEL = -99; //Code for exiting loop
int main()
{
int numbers; //variables
int large;
int small;
int smallest = 0;
int counter;
int largest = 0;
int next;
char letter;
bool quit = false;
while(!quit)
{
cout << "A - Find the largest # with a set quantity of numbers. \n"; //this is the program initiating
cout << "B - Find the smallest # with an unknown quantity of numbers. \n";
cout << "C - Quit Program. \n";
cout << "Please enter your choice: ";
cin >> letter; //choice is inputted
switch (letter)
{
case 'A':
cout << "Enter the number of numbers to be compared. \n";
cin >> numbers;
cout << "Enter the numbers please:";
cin >> large;
largest = large;
for (counter = 0; counter < numbers-1; counter++)
{
cin >> next;
if (largest < next)
{
largest = next;
}
}
cout << "The largest number you entered was. \n";
cout << largest << endl; //code for the largest number inputted
break;
case 'B':
cout << "Enter numbers, the smallest number entered of all the numbers will be displayed. \n To exit and receive answer, enter -99" << endl;
cin >> small;
smallest = small;
while (next != -99)
{
cin >> next;
if (smallest > next && next != -99)
{
smallest = next;
}
}
cout << "The smallest number you entered was. \n";
cout << smallest << endl; //code for the smallest number inputted
break;
case 'C':
quit = true;
break;
}
cout << endl;
}
return 0;
}