Go4Expert (http://www.go4expert.com/)
-   C++ (http://www.go4expert.com/forums/cpp/)
-   -   please can someone correct this code (http://www.go4expert.com/forums/correct-code-t16653/)

 Gaylle 25Mar2009 00:58

please can someone correct this code

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; }```

 xpi0t0s 25Mar2009 05:25

Re: please can someone correct this code

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.

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 30Mar2009 21:12

Re: please can someone correct this code

i hadnt solved the problem like u think. i'm just doin it now. am grateful you pointed out my mistake tho. tnx

 xpi0t0s 31Mar2009 03:23

Re: please can someone correct this code

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.

 All times are GMT +5.5. The time now is 14:01.