I need help with some homework.
I need to write a program that uses 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.


If anyone can help or guide me how to do this. It would be helpful. It might seem trivual to some of you, but I am not sure how to write this up. :cry: :cry:

Start at the beginning. Go from a blank source file to one with header(s) and a main function. Add some of the requirements that were heavily hinted. Post what you have and issues you are having.

alternatively, forget you are writing this for the computer for a while and use a pencil to write down what needs to get done when. When you can write it out on paper then you can change it into code.

For example, you could start real general like this:

enter header files
write main function
declare variables and initialize as appropriate
start while loop
ask for input
store input in appropriate variable
compare current number to largest number
adjust largest number if needed
increment counter
end while loop
display results of body of loop
end main function

Then use the above as comments and get more specific until you have written the code.

this is what I have so far!!!! any help would be helpful.

#include <iostream>

using namespace std;

void main ()
{
int counter = 1;
int number;
int largest;
	
while (counter <= 10);
{
	cout << "Enter a number \n";
	cin >> number;
}
return ;
}

this is what I have so far!!!! any help would be helpful.

#include <iostream>

using namespace std;

void main ()
{
int counter = 1;
int number;
int largest;
	
while (counter <= 10);
{
	cout << "Enter a number \n";
	cin >> number;
}
return ;
}

First, main returns an int, so the basic shell is like this:

#include <iostream>
using namespace std;

int main ()
{
   // do stuff
   return 0;
}

Here, you may notice that you keep taking input to the same integer:

cin >> number;

That can be fine, but when the next number is input the previous value is discarded. So if you want to keep track of it in some way, you'll need to do so. For example, it you want to find the largest, you might want to compare with the currect value of the largest with the current input and see if the current input is bigger that the current largest.

The palindrome stuff suggests keeping all of the values in some way (such as an array), but let's working on simpler stuff first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.