please can someone correct this code

Gaylle's Avatar, Join Date: Mar 2009
Light Poster
my answers are wrong. dont know what is wrong with the code though there are no build errors.


Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    //declarations
    int operation;
    double CirRadius, CirArea, Base, Height, TriArea;
    const double PI = 3.14159;

    // menu
    cin >> operation;
    while (operation !=4)
    {
        if (operation == 1)
        {
            cin >> CirRadius;
              CirArea = PI * CirRadius * CirRadius;
            cout<<"The area of a circle with radius "<<CirRadius<<" is " <<setprecision(4)<<CirArea<<'\n\n';
            cin >> operation;
        }
        else if (operation == 2 || operation == 3)
        {
            cin >> Base;
            cin >> Height;
            TriArea = 0.5 * Base * Height;
            cout<<"The area of a triangle with base "<<Base<<" and height "<<Height<<" is "<<TriArea<<'\n\n';
            cin >> operation;
        }
        else if (operation == 5 || operation == 7)
        {
            cout<<"Error: "<<operation<<" is not a valid operation.\n\n";

        }
        
    }

    return 0;
}

Last edited by shabbir; 31Mar2009 at 07:56.. Reason: Code blocks
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Use code tags when posting code.
In what way are the answers wrong? What data did you enter, what results did you expect, and what results did you get?

From your other post I guess it's probably something to do with this line:
Code:
else if (operation == 2 || operation == 3)
2 is a rectangle, isn't it?



Hmm.
Dammit, another duplicate.
http://www.go4expert.com/showthread.php?t=16651

I'm going to stop wasting my time on solving the problems you've already solved but can't be arsed to tell us you've solved them.
Gaylle's Avatar, Join Date: Mar 2009
Light Poster
i hadnt solved the problem like u think. i'm just doin it now. am grateful you pointed out my mistake tho. tnx
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Where are you up to? Could you (restricting posts on this code to this thread only) post the code you've got so far, with code tags, and explain what the problem is, what input you gave if you're getting wrong results, what output you expected and what output you got.