Hi, I've written this code and I've run into a few problems. I got it to run
but when it comes time for the user to enter the selection, it just keeps
going down the line of switch functions such as if I enter 1 as a selection it
goes to the area of the circle, but if i put in any number it automatically
goes to the length of the rectangle, then the width, etc. I'm trying to run
the math equations after the initial selection but I'm not sure how to do
that. I'm pretty sure i have to somehow link the math equations with the
selection but when i tried doing that it gave me an error. Under the math
equations i originally had
1=Circle2=Rectangle3=Triangle
However that gave me an error so I took it out to see how the program would
run without it. The program ran but then i ran into the above mentioned
problem. Anyway I'm completely lost and this is way past due for class so any
help would be appreciated. Here's the code:
#include <iostream>#include <math.h>#include<stdio.h>usingnamespacestd;
intmain()
{
intnumber1;
intnumber2;
intnumber3;
intnumber4;
floatCircle;
floatRectangle;
floatTriangle;
intchoice;
doublepi;
floatlength;
floatwidth;
floatbase;
floatheight;
floatradius;
number1 = 1;
number2 = 2;
number3 = 3;
number4 = 4;
pi = 3.14159;
Circle = pi * radius * radius;
Rectangle = length * width;
Triangle = base * height * .5;
cout<< "Geometry Calculator" << endl;cout << "1. Calculate the Area of a Circle" << endl;cout << "2. Calculate the Area of a Rectangle" << endl;cout << "3. Calculate the Area of a Triangle" << endl;cout << "4. Quit" << endl << endl;cout << "Enter your choice (1-4):" << endl;cin >>choice;
switch(choice)
{
case1 : cout<< "Enter the radius of the circle:" << endl; cin >>radius;
case2 : cout<< "Enter the length of the rectangle:" << endl; cin >>length;
cout<< "Enter the width of the rectangle:" << endl; cin >>width;
case3 : cout<< "Enter the height of the triangle:" << endl; cin >>height;
case4 : cout << "Goodbye!" << endl;
default:cout << "5 is not a valid entry." << endl;
}
return0;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Unlike say Pascal, in C/C++ a case is not terminated by the presence of the
next case. If you do not want the case to "fall through", you need to
terminate it with a break statement.
case1:cout<<"Enter the radius of the circle:"<<endl;cin>>radius;break;case2:...break;//etc.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to run the math equations after the initial selection but I'm not
sure how to do that. I'm pretty sure i have to somehow link the math equations
with the selection but when i tried doing that it gave me an error.
Hi, I've written this code and I've run into a few problems. I got it to run
but when it comes time for the user to enter the selection, it just keeps
going down the line of switch functions such as if I enter 1 as a selection it
goes to the area of the circle, but if i put in any number it automatically
goes to the length of the rectangle, then the width, etc. I'm trying to run
the math equations after the initial selection but I'm not sure how to do
that. I'm pretty sure i have to somehow link the math equations with the
selection but when i tried doing that it gave me an error. Under the math
equations i originally had
However that gave me an error so I took it out to see how the program would
run without it. The program ran but then i ran into the above mentioned
problem. Anyway I'm completely lost and this is way past due for class so any
help would be appreciated. Here's the code:
Unlike say Pascal, in C/C++ a case is not terminated by the presence of the
next case. If you do not want the case to "fall through", you need to
terminate it with a break statement.
hi,
I'm trying to run the math equations after the initial selection but I'm not
sure how to do that. I'm pretty sure i have to somehow link the math equations
with the selection but when i tried doing that it gave me an error.
regards,
phe9oxis,
http://www.guidebuddha.com