I have to modify that same code 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. I need to use void greatest(). Any assistance would be greatly appreciated.
//marks the end of the data being read
const int SENTINEL = -99;
int main()
{
//Declare your variables
int n = 0; //variable to store number
int A = 0; //variable for starting option A's choice & stores the numbers entered
char userinput; //variable store user's choice
int temporary = 0; //variable stores numbers entered for choice A
int B = 0; //variable for starting option B's choice & stores the numbers entered
int C = 0; //variable for starting option C's choice
int smallest = 999999999; //variable to store smallest number for choice B
int largest;
do {
//how the menu choices will be displayed
cout << "++++++++++++++++++++++++++++++++" << endl;
cout << " Program Menu Display " << endl
<< "++++++++++++++++++++++++++++++++" << endl
<< " A) Find the largest number " << endl
<< " B) Find the smallest number " << endl
<< " C) Quit " << endl
<< "+++++++++++++++++++++++++++++" << endl;
//output of user's choice
cout << "Please enter your choice here > "; //enter your choice of A or B or C on the blinking cursor
//then press the enter button to start the program of choice.
cin >> userinput;
switch(userinput)
{
case 'a': //for the use of lowercase letter input
case 'A': //for the use of uppercase letter input
cout << "Please choose how many numbers you want > "; //enter on the blinking cursor how many numbers
//you want to use
cin >> n;
void largest();
for(int i = 0; i < n; i++) //outputs a line of numbers
{
temporary = A;
cout << "Please enter the next number "; //enter each number on the blinking cursor then press enter button.
cin >> A;
if(temporary > A) //if temporary is greater than A
{
A = temporary;
}
}
cout << "The largest number entered was " << A << endl; //after all the numbers are chosen the largest number
//will be generated as the end result.
break; //terminates the loop
case 'b': //for the use of lowercase letter input
case 'B': //for the use of uppercase letter input
cout << "Please pick your first number to start with > "; //output data
cin >> B; //input data
while(B != SENTINEL) //test the loop control variable
{
if(B < smallest) //if B is less than smallest number it replaced
smallest = B;
//(After entering all the numbers you want to use
// enter integer -99 to quit the program)
cout << "Please enter the next number > "; //output data
cin >> B; //input data
}
cout << "The smallest number entered was " << smallest << endl; //after -99 has been entered all the numbers that have
// been entered the smallest number will be generated as the end result.
break; //terminates the loop
case 'c': //for the use of lowercase letter input
case 'C': //for the use of uppercase letter input
cout << "Thank you for running my program " << endl; // when chosing option C the program will end
break; //terminates the loop
default:
cout << "You made an invalid choice " << endl; //if anything besides the choices is entered will receive this message
break; //terminates the loop
}
}while (userinput != 'C' && userinput != 'c'); //while userinput is not equal to C or c will quit the program
I have to create a void function for this program and I am clueless on where that is supposed to go. The example that was given is this:
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 greater than final result variable, then
//store in final result variable
//end of loop
}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 greater than final result variable, then
//store in final result variable
//end of loop
}
The function for A should have the quantity of numbers passed in as a parameter and needs to return the largest number.
As U need to have the A function that returns void as well you need this method to give you the largest number, so U can use the "pass by reference" concept for the largest variable.
This should give you some ideas on where to start, please ask more questions if you still need more help.
It can be difficult to answer general questions like the one above as we do not know what level of answer you require - In C++ there will often be many possible ways to solve a given simple problem so the more help you can give us (in terms of explaining the problem, any ideas for possible solutions etc.) the better we can help you.
When posting code into the forum, please use the 'Insert Code' button (just below the edit box).
it will paste a couple of tags into the edit box, '[ Code ]' and '[ /Code ]' (but without the spaces). Put your code between thes tags and the result is
1 2 3 4 5 6
int main()
{
//This is a cormatted code example!
cout << "Hello World" << endl;
return 0;
}
If I was to translate that pseudo into code it'd be:
1 2 3 4 5 6 7 8 9 10 11 12 13
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 greater than final result variable, then
//store in final result variable
//end of loop
}void greatest()
#include <iostream>
usingnamespace std;
void greatest() {
int iBiggest = 0;
int iCurrent = 0;
int iNumberToEnter = 0;
cout << "How many number do you want? ";
cin >> iNumberToEnter;
for (int i = 0; i < iNumberToEnter; ++i) {
cout << "Please enter Number: ";
cin >> iCurrent;
if (iCurrent > iBiggest)
iBiggest = iCurrent;
}
cout << "The biggest number you entered was " << iBiggest << endl;
}
int main() {
greatest();
return 0;
}
i think there should be function overloading....
lets start like this,.....
#include<iostream.h>
#include<conio.h>
class greatest
{
private: int a;
int b;
public: greatest();
greatest(A)
}
greatest::greatest()
{
statement...
return smallest;
}
greatest::greatest(A)
{
statement....
return greatest;
}
int main()
{
//statements and function call be declared here
}
happy programming!!!!!