Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;
       }
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote