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; }
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Leave a comment