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; }
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.
i hadnt solved the problem like u think. i'm just doin it now. am grateful you pointed out my mistake tho. tnx
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.