198k views
2 votes
Which line in the following program will cause a compiler error?

1 #include
2 using namespace std;
3 int main()
4 {
5 int number = 5;
6 if (number >= 0 && <= 100)
7 cout << "passed.\\";
8 else
9 cout << "failed.\\";
10 return 0;
11 }
a. line 3
b. line 6
c. line 7
d. line 9
e. None will cause an error

1 Answer

4 votes

Final answer:

The line that will cause a compiler error is line 6.

Step-by-step explanation:

The line that will cause a compiler error is line 6.

The line if (number >= 0 && <= 100) is missing a variable to compare to 100. It should be written as if (number >= 0 && number <= 100). The compiler needs both sides of the comparison operator to have a value.

The corrected code would be:

#include <iostream>
using namespace std;

int main() {
int number = 5;
if (number >= 0 && number <= 100)
cout << "passed.\\";
else
cout << "failed.\\";
return 0;
}

User Guillermo Gomez
by
8.7k points