vendredi 19 juin 2015

C++ Logicial Operators ( Could someone Explain and help)

So I have written a small program to work out the perimeter of simple shapes (very new to coding so keeping it simple). I am now stuck though the code works up too triangle and I can't for the life of me work out how to get the last logical operator to work!!!? As always greatly appreciate your time and advice Best regards Jake

#include <iostream>
#include <string>
using namespace std;
int main ()
{   
    int length;
    int Diameter;
    float Pi = 3.14;
    string Shape;
    string Square = "Square";
    string Triangle = "Triangle";
    string Circle = "Circle";          

    cout <<"=======================" << endl;
    cout <<"=Welcome to Perimeters=" << endl;
    cout <<"#######################" << endl;
    cout <<"###|Select A Shape|####" << endl; 
    cout <<"=======================" << endl;
    cout <<"=   |   Circle   |    =" << endl;
    cout <<"=   |  Triangle  |    =" << endl;   
    cout <<"=   |   Square   |    =" << endl;
    cout <<"=======================" << endl;


    cout <<"Enter Shape >; ";
    cin >> Shape;

    if (Shape == "Square") {
        cout << "Enter Length of Side >: ";
        cin >> length;
        cout <<  "Perimeter = " ; 
        cout << length * 4 <<endl;
    } else {
             (Shape == "Triangle"){ 
             cout << "Enter Length of Side >: ";
             cin >> length;
             cout <<  "Perimeter = " ; 
             cout << length * 3 <<endl;
             }    

            }   
            else  {
                    (Shape == "Circle") { 
                    cout << "Enter Diameter >: ";
                    cin >> Diameter;
                    cout <<  "Perimeter = " ; 
                    cout << Diameter * Pi <<endl;
                    }

                   }




    return 0;
}

Aucun commentaire:

Enregistrer un commentaire