66 999
Assignments Done
99,2%
Successfully Done
In November 2018

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)
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions