Answer to Question #26875 in C++ for red rose
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)
using namespace std;
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;
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!