i am trying to make a program that asks the user to type 10 integers and writes the highest value but i can just write 10 integers. how can i do this ? please, i need help
So you want to find the largest number out of 10 integers, eh? It's relatively straightforward. This example does such an operation:
1 2 3 4 5 6 7 8 9 10
int FindLargest( constint( &IntArray )[10] )
{
int Largest( IntArray[0] );
for( short i( 0 ); i < 10; i++ )
if( Largest < IntArray[i] )
Largest = IntArray[i];
return Largest;
}
This code is simple to understand. The single parameter is a reference to an array of 10 integers. The parentheses enclosing &IntArray are required, otherwise, the compiler will think it's an array of 10 references to integers. The local variable, Largest, stores the largest number within IntArray. Its functionality becomes obvious within the for loop construct. Next, a for loop is entered, which loops 10 times. The if statement is used to determine if the value stored within Largest is less than the ith value within IntArray. If it is, Largest then obtains the ith value of IntArray.
If the user is entering these values during runtime you simply store two numbers. int highest, user;
Set highest to the first input automatically. Then simply loop comparing the users input with highest in an if statement. If the user is greater than the current highest, set highest to the user.
Once all ten numbers are entered, simply print the value of highest.
Your compiler and IDE is very old. Chances are, it doesn't support references to arrays. You need a more up-to-date IDE such as Microsoft Visual C++ 2010/2008, or Code::Blocks.