dimanche 18 février 2018

I have difficulties writing code for this assignment for if/else statement. This is first programming class

Write a program that calculates the areas of 2 triangles. Ask the user for the base and height of each triangle. Print the areas of both triangles. The program should tell the user which triangle has the larger area, or if the areas are the same. ERROR CHECKING: The user should not be allowed to enter a negative number for base or height, so validate the input.

This is what I have done so far but, my program does not compile.

#include <iostream>
using namespace std;

int main()

{
    double  baseOne, baseTwo, heightOne, heightTwo, areaOne, areaTwo, i1;

    cout << "Please enter the base and height of first triangle\n";

    cin >> baseOne, heightOne;

    if (baseOne <= 0 && heightOne <= 0)
    {
        cout << "Your value is invalid!!\n";
    }
    else
    {
        cout << "What is the length of first triangle?\n";
        cin >> baseOne, heightOne;
        areaOne = (baseOne * heightOne) / 2;

        cout << "Area of the first triangle is" << areaOne << endl;

    }
    cout << "What is the base and height of second triangle\n";

    cin >> baseTwo, heightTwo;

    if (baseTwo <= 0 && heightTwo <= 0)
    {
        cout << "Your value is invalid!!\n";
    }
    else
    {
        cout << "What is the length of first triangle?\n";
        cin >> baseTwo, heightTwo;
        areaTwo = (baseTwo * heightTwo) / 2;

        cout << "Area of the first triangle is" << areaTwo << endl;

    }

    if (areaOne > areaTwo)
    {
        cout << "Area One is larger with " << areaOne << "than area two\n";
    }
    else if (areaOne < areaTwo)
    {
        cout << "Area Two is larger with" << areaTwo << "than area one\n";

    }

    else
        areaOne == areaTwo;
    areaOne = i1;
    cout << "Magnitude of area one and area two is same with " << i1 <<< endl;

    system("pause");
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire