Highest Number Errors

My code is designed to pick the highest number out of five inputted integers and display it to the user, but I'm getting several errors throughout lines 31 - 63.

I am using Visual Studio 2008 Express Edition to compile.

Code:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <iostream>
using namespace std;

int main() {
	//Variables
	int iInput[6] = {0,0,0,0,0,0};
	int iInputLoop = 1;
	int iHighestNumber;

	//Input while loop
	cout << "Enter 5 numbers: ";
	while( iInputLoop < 6 ) {	
		cin >> iInput[iInputLoop];
		system("CLS");
		cout << iInput[1] << ", " << iInput[2] << ", " << iInput[3] << ", " << iInput[4] << ", " << iInput[5] << "." << endl;
		cout << "> ";
		iInputLoop++;
	} //end Input while loop

	//Wait for enter
	cin.sync();
	cin.get();
	
	system("CLS");
	cout << "Now finding highest number. . .";

	//Find highest number
	if( iInput[1] > iInput[2] &&
		iInput[1] > iInput[3] &&
		iInput[1] > iInput[4] &&
		iInput[1] > iInput[5] && ) {

			iHighestNumber = iInput[1];
	} //end if

	else if( iInput[2] > iInput[1] &&
			 iInput[2] > iInput[3] &&
			 iInput[2] > iInput[4] &&
			 iInput[2] > iInput[5] && ) {

				 iHighestNumber = iInput[2];
	} //end if

	else if( iInput[3] > iInput[1] &&
			 iInput[3] > iInput[2] &&
			 iInput[3] > iInput[4] &&
			 iInput[3] > iInput[5] && ) {

				 iHighestNumber = iInput[3];
	} //end if

	else if( iInput[4] > iInput[1] &&
			 iInput[4] > iInput[2] &&
			 iInput[4] > iInput[3] &&
			 iInput[4] > iInput[5] && ) {

				 iHighestNumber = iInput[4];
	} //end if

	else if( iInput[5] > iInput[1] &&
			 iInput[5] > iInput[2] &&
			 iInput[5] > iInput[3] &&
			 iInput[5] > iInput[4] && ) {

				 iHighestNumber = iInput[5];
	} //end if

	cout << endl << endl << endl;
	cout << "Press enter for the highest number!";
	cin.get();
	system("CLS");
	cout << "Your original numbers were: ";
	for( int iOutputLoop = 1; iOutputLoop < 6; iOutputLoop++ )
		cout << iInput[iOutputLoop] << ", ";

	cout << endl << endl;
	iHighestNumber = iInput[1];
	cout << "The highest number is '" << iHighestNumber << "' !";

	cin.get();

	
	
	return 0;
}




Errors:


1>------ Build started: Project: HighestNumber_A1, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(31) : error C2059: syntax error : ')'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(31) : error C2143: syntax error : missing ';' before '{'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(36) : error C2181: illegal else without matching if
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(39) : error C2059: syntax error : ')'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(39) : error C2143: syntax error : missing ';' before '{'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(44) : error C2181: illegal else without matching if
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(47) : error C2059: syntax error : ')'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(47) : error C2143: syntax error : missing ';' before '{'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(52) : error C2181: illegal else without matching if
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(55) : error C2059: syntax error : ')'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(55) : error C2143: syntax error : missing ';' before '{'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(60) : error C2181: illegal else without matching if
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(63) : error C2059: syntax error : ')'
1>c:\users\brad\desktop\c++ projects\highestnumber_a1\highestnumber_a1\main.cpp(63) : error C2143: syntax error : missing ';' before '{'

1>Build log was saved at "file://c:\Users\Brad\Desktop\C++ Projects\HighestNumber_A1\HighestNumber_A1\Debug\BuildLog.htm"
1>HighestNumber_A1 - 14 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========



Any ideas?


Last edited on
You have an extra && after the last part of your if statements. It looks like the only error.

EDIT: Also, you could just check to see if the number is > iHighestNumber instead of checking all the other numbers.
Last edited on
Well how would I do it if those are checking what the highest number is?
Instead of doing a bunch of else ifs, just do this:

1
2
3
4
iHighestNumber = iInput[1];
for(int i 2; i < 4; ++i) {
   if(iInput[i] > iHighestNumber) iHighestNumber = iInput[i];
}
Thanks! That worked perfectly, and shortened my code greatly. :)
Last edited on
Topic archived. No new replies allowed.