Hello, everyone.
I am having a little trouble coding while statements to get results from the rest of the code. At present I am attempting to determine the largest of 10 integers entered by a user from the keyboard.
I have constructed the While Statement, using an if statement in the body of the while, to determine the largest integer. However, I get numerous errors.
The code I have thus far constructed is reproduced below.
CODE
// Program 4.17_b.cpp: This program uses a while statement to determine and print the largest of 10 numbers entered by a user from the keyboard.
#include <iostream>
// Declare using declarations
using std::cout;
using std::cin;
using std::endl;
int main() // Begin program execution
{
// Initialize variables
int counter = 1;
int num;
int largest = 0;
while (counter <= 10) // Begin while loop
{
cout << "Please enter a number from the keyboard.\n" << endl; // Prompt user to enter a number from the keyboard
cin >> num; // Read in number entered by user
int largest = num;
if (int num > largest) // Begin loop to determine the largest of 10 numbers entered by user from the keyboard
cout << "\n" << largest << "\n" << endl; // Determine if first number entered by user from keyboard is largest, then output that number
counter++; // Advance counter by 1 for each loop
} // End while loop
cout << "\nThe largest of the numbers entered is " << num << "." << endl;
return 0; // Terminate program successfully
} // End main and program execution
With the code constructed like the above, I get a syntax error #2059 '>' for the if statement.
I have rearranged the code several different ways, and each time I get an error, like I need a semi-colon or a comma before the if statement. Therefore, I must be constructing the if statement wrong. I also tried an if/else statement, but I get the error next to the else that it is illegal and missing an if.
I understand what I need to do in this problem, but my mind is not picking up on how to construct the code to find the largest number.
A little help from anyone would be greatly appreciated.
Thanks.
Uncle Scruffy