Answer to Question #26875 in C++ for red rose

Question #26875
Write a C++ program that selects and displays the maximum value of five numbers to be entered when the program is executed.
(Hint: Use a for loop with both a cin and if statement inside the loop)
1
Expert's answer
2013-03-25T09:24:04-0400
#include <iostream>

using namespace std;

int main()
{
int number;
int maxNumber = -1;

cout << "Enter 5 numbers: ";
for (int n = 0; n < 5; n++)
{
cin >> number; //read next number
if (number > maxNumber) //check if it's bigger than maxNumber
maxNumber = number;
}

/* Print the maximum value */
cout << endl;
cout << "The largest number is: " << maxNumber << endl;
return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS