If-not statement?

I am writing a basic calculator for fun, and I am on to geometry. Here is my shape section.

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
cout << "You need to find the area of a square, a rectangle, a trapezoid, a parallelogram, or a triangle? ";
		cin >> shape;
		
		if(shape=="square"){
			cout << "Enter the length of one side: ";
			cin >> side;
			answ = side * side;
			cout << "The area of the square is: " << answ;
			
		}
		
		if(shape=="rectangle"){
			cout << "Enter the base: ";
			cin >> base;
			cout << "Enter the height: ";
			cin >> height;
			answ = base * height;
			cout << "The area of the rectangle is " << answ;
		}
		
		if(shape=="trapezoid"){
			cout << "Enter base one: ";
			cin >> base1;
			cout << "Enter base two: ";
			cin >> base2;
			cout << "Enter the height: ";
			cin >> height;
			
			answ = .5 * (base1+base2) * height;
			
			cout << "The area of the trapezoid is " << answ;
			
		}
		
		if(shape=="parallelogram"){
			cout << "Enter the base: ";
			cin >> base;
			cout << "Enter the height: ";
			cin >> height;
			answ = base * height;
			cout << "The area of your parallelogram is " << answ;
		}
		
		if(shape=="triangle"){
			cout << "Enter the base: ";
			cin >> base;
			cout << "Enter the height: ";
			cin >> height;
			answ = .5*(base*height);
			cout << "The area of your triangle is " << answ;
		}


I want to make it so if the shape isn't either of the ones I programmed, or just random text, that it will print something similar to "Invalid input"

You can do this by using if-else statements.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

if (shape == "square")
{
     //Do calculations here
}

else if (shape == "rectangle")
{
     //Do calcs here
}

//..... Do else if statements for all shapes you want to include in your program
//finally:
else
{
     cout << "Invalid input" << endl;
}
You can use else if chains for this.

1
2
3
if(x) { }
else if(y) { }
else { } // x and y are both false here if this runs 
Thanks guys :)
I went with CodingKid's method, worked like a charm.
Topic archived. No new replies allowed.