getting error with else if statement

closed account (D4NbpfjN)
I am getting an error with the else if statement. It is underlining the else and saying expected a statement. Could someone tell me what i am doing wrong thanks.

1
2
3
 else if ((choice < 1) || (choice > 5));
cout << "Error, please choose from the correct choices: ";
			
There is a semicolon at the end of the else if statement, remove it and it should work.
Last edited on
closed account (D4NbpfjN)
This is my entire code. i am still getting an error after removing the semicolon.



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
#include<iostream>
using namespace std;
int main()
{
	float radius, length, width, area;
	char choice;
	do {
		std::cout << "Please choose from the choices listed\n";
		std::cout << "1 --Area of a square\n";
		std::cout << "2 -- Area of a circle\n";
		std::cout << "3 -- Area of a right triangle\n";
		std::cout << "4 -- Quit\n";
		std::cin >> choice;

		if (choice == '1')
		{
			float length;
			std::cout << "Enter length of square.";
			std::cin >> length;
			std::cout << "Area of the square =" << length*length << "\n\n";
		}
		else if (choice == '2')
	{
			float radius;
			std::cout << "Enter the radius of the circle: ";
			std::cin >> radius;
			std::cout << "Area of a circle is =" << 3.142*radius*radius << "\n\n";
		}
		else if (choice == '3')
		{
			float width;
			std::cout << "Enter the length of the right triangle:";
			std::cin >> length;
			std::cout << "Enter the width of the right traingle: ";
			std::cin >> width;
			std::cout << "Area of the right triangle =" << length*width / 2 << "\n\n";
		
			
		else if ((choice < 1) || (choice > 5))
			cout << "Error, please choose from the correct choices: ";
			
		
		}

		

	}
	
	while (choice != '4');




	


	return 0; 


}
The errors are at line 38: missing closing brace }
and line 43: extra closing brace }
Topic archived. No new replies allowed.