Trouble with using if else.

Hey guys, i was assigned to determine which area is larger depending on what the user inputs by using a if statement we just learned this in class and i have some confusion on why it cannot run. Would really appreciate it if someone can help me with this thanks!

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
  // Application Name: Areas of a rectangle.
// Programmer: Juan Gutierrez
// Date: 11/1/2016
// Purpose: Determine which rectangle's area is bigger after the user inputs there sides.

#include <iostream>


using namespace std;

int main()
{
	//Stating the int's both sides for both rectangles, and both of there areas.

	double length1, length2, width1, width2, area1, area2;

	//Asking the user for the sides of both rectangles.

	cout << "Please input the length and width of the first rectangle:" << endl;
	cin >> length1, width1;

	cout << "Now input the length and width of the second rectangle:" << endl;
	cin >> length2, width2;

	//Using the equation to get the area of a rectangle.
	
	area1 = length1 * width1;
	area2 = length2 * width2;

	//Stating that which area is larger or the same by using a if  statement.

	if (area1 > area2) {
		cout << "The first rectangle has a greater area." << endl;

	if else (area2 > area1)
			cout << "The second rectangle has a greater area." << endl;


	else
		cout << "Both area's are equal." << endl;
	}






	return 0;
}
first of all cin >> length1>>width1;
and
1
2
3
4
5
6
7
8
9
10
if (area1 > area2) {
		cout << "The first rectangle has a greater area." << endl;
	}

	else if(area2 > area1)
			cout << "The second rectangle has a greater area." << endl;


	else
		cout << "Both area's are equal." << endl;
Last edited on
Thanks!One more question, when would multiple brackets be used?
I don't quite understand what you mean, give an example.
Topic archived. No new replies allowed.