CinMax.cpp

// loops/cin-max-flakey.cpp - Finds max int in input.
// Purpose of this example.
// 1. To illustrate algorithm to find maximum.
// 2. To show common problems to be fixed in loops/cin-max-robust.cpp
// Eg, what happens if all numbers are negative? No input?
// Fred Swartz - 2003-08-28

#include <iostream>
using namespace std;

int main() {
int max = 0;
int n;

while (cin >> n) {
if (n > max) {
max = n;
}
}

cout << "Maximum is " << max << endl;

system("pause");
}

Post a Comment

0 Comments