I just started class about 4 wks ago. I just got my deitel's c++ how to program book and I already cannot figure out how to do this homework assignment... (I got shiested online...getting refund, just had to purchase book late.)

use a while statement to determine and print the largest number of 10 numbers input by the user. The program should use three variables:

counter: A counter to count to 10, (to keep track of how many numbers have been input and to determine when all numbers have been processed.)

number: the current number input to the program

Largest: The largerst number found so far.

Now..from what I have, I don't quite understand how to put the while loops to find the largest # out of the 10 entered....heres what I have after working on this for 3 hrs!!! I got an error message on the while part...on that line. I've got a headache too!

as im reading...i think what i can't find is where to assign the values to the counter (if im saying that right)...

Thanks!
ps...IM NEW I SAID!!! DON'T BE LAUGHIN.....:lol:

#include <iostream>
using namespace std;
int main ()
{

int counter; 	
int larger;
int number; 

if   ( number < 10 )
cin << largest < number;

while 


{
cout << "enter your number: " ; 
cin >> number;
}
//end of while loop

return 0;
}

See this

#include <iostream>
using namespace std;
int main ()
{

int counter=0;
int largest=0;
int number=0;
largest=number;

while ( counter < 10 )
{
    cin>>number;
    if(largest<number) 
        largest = number;
    ++counter;
}
cout<<"Largest Number:"<<largest;

return 0;
}

thanks so much! You will not believe if I hadda started reading chapter 5 before I asked this question, I probably would had understood it better then...chap. 5 covers this in detail!!! :eek:
I modified it just a bit but it did work. I couldn't figure out what what the if statement was supposed to say and how it worked. when I read yours aloud, It made perfect sense. again, thanks for your help. I also have to now modify it to the " do- while" loop!

I hope one of these days I can help too...(one day...:-| )

This article has been dead for over six months. Start a new discussion instead.