### If-not statement?

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

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051`` ``````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.

 ``123456789101112131415161718`` `````` 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.

 ``123`` ``````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.