C++ Write functions to do the following. Do not change the function signature. P
ID: 3668579 • Letter: C
Question
C++
Write functions to do the following. Do not change the function signature. Please write the functions, using the given function signature and specifications.
Write a function that reads positive numbers from the user, and returns the largest number and outputs it. The function signature should be
int largest();
The function does not take any parameters. So, you can read all your input in the function. It returns an int, which is the largest number to main. Use a loop to read the numbers until the user enters -1 to quit. As you read, keep track of the largest number. When the user enters -1, stop reading and return the largest number to the main function. Do NOT use an array for this program.
Explanation / Answer
int largest()
{
int x=0;
int max=-1;
while(true)
{
cin>>x;
if(x==-1)
{
return max;
}
if(x>max)
{
max=x;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.