The Maximum of a Group of Numbers

Problem: Write a pseudocode program, then a C++ program that uses a while statement to determine and print the largest number of 10 numbers input by the user. Your program should use three variables, as follows:

counter
number
largest

Here is the program I wrote:

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int main()
{
int counter = 1;
int number =0;
int largest = 0;



while ( counter <= 10 )
{
counter = counter + 1;
cout << "Enter a number: " ;
cin >> number;

if ( number > largest )
number = largest;
}

cout << "\nThe largest number you have entered is " << largest << "." << endl;

return 0;
}


MY PROBLEM is that it's not printing the largest number. Instead it's printing 0, which is the number I have declared for the variable largest. Is something wrong with my IF statement???

Thanks. I appreciate any input.
The assignment operator is being used incorrectly...you have:

number = largest;

This means, assign whatever largest is to number. You want to flip it.
Thanks a lot! Never occurred to me that I was using it wrong. BIG thanks!
Topic archived. No new replies allowed.