geometry calculator

keeps failing but i can't figure out why. can someone please help me

instructions:
Geometry Calculator: Write a C++ program that displays the following menu: GEOMETRY CALCULATOR
1. Calculate the Area of a Circle
2. Calculate the Area of a Rectangle
3. Calculate the Area of a Triangle
4. Quit Enter your choice (1 – 4): If the user enters 1, the program should ask for the radius of the circle and then display its area.
Area = πr2
If the user enters 2, the program should ask for the length and width of the rectangle and then display rectangle’s area.
Area = length × width
If the user enters 3, the program should ask for the length of the triangle’s base and its height, and then displays its area.
Area = base × height × 0.5
Note: Do not accept negative values for the circle’s radius, the rectangle’s length or width, or the triangle’s base or height.


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


#include <iostream>
#include <math.h>


int main
{
const double PI = 3.14;
// geometry calculator

// calculate the area of a circle
cout << "enter 1 for radious of a circle" << radious << "enter the area of a circle" << areaC << endl;

// calculate the area of a rectangle
cout << "enter 2 for length of rectangle" << length << "enter the width of a rectangle" << width << "enter the area of a rectangle" << areaR << endl;

// calculate the area of a triangle
cout << "enter 3 for base of a triangle" << base << "enter height of the triangle" << height << "enter area of the triangle" << areaT << endl;

// quit
cout << "enter 4 to quit" << quit << endl;

case 1:
cout << "enter the radious of a circle \n";
cin >> radious
cout << "enter the area of a circle\n"
cin >> areaC;
cout << "the area of the circle is " << areaC << endl;
break;

case 2:
cout << "enter the length of the rectangle" << length << endl;
cin >> length;
cout << "enter the width of the rectangle" << width << endl;
cin >> width;
cout >> areaR
areaR = a * b;
cout >> "the area of the rectangle is " << areaR << endl;
break;

case 3:
cout << "enter the base of the triangle" << base << endl;
cin >> base;
cout >> "enter the height of the traingle" << height << endl;
cin >> height;
s = (a + b + c) / 2
areaT = sqrt (s * (s-a) * (s-b) * (s-c));
cout >> "The area of the triangle is " << areaT << endl;
cin >> areaT
break;

case 4:
cout << "program quit" << quit << endl;
cin >> quit;
return 0;
}
Hi, there is a lot of problems with this code. The first most obvious one is you have no cin >> for the user to input a number. I'm assuming your program will not compile because of your syntax on your switch statement?

Since the user cannot input an initial 1-4 then the program will not advance to your switch statement. Even if you include this, your program still will not compile, because your switch syntax is wrong.

Hints;
Declare an int for your initial cin>> input.

your switch needs to be formatted such as :

switch(what ever your declared int is)
{
body of switch
}

One more hint, unless the instructions were to use the value 3.14 for pi, it's better to use const double PI = acos(-1.0).

Hope this helps.
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
	const double PI = 3.14;
	double areaofC, areaofR, areaofT;
	int x, radiousofC, lengthofR, widthofR, baseofT, heightofT;
	// geometry calculator
	
	// calculate the area of a circle
	cout << "enter 1 for area of a circle" << endl;
	
	// calculate the area of a rectangle
	cout << "enter 2 for area of a rectangle" << endl;
	
	// calculate the area of a triangle
	cout << "enter 3 for area of a triangle" << endl;
	
	// quit
	cout << "enter 4 to quit" << endl;
	
	cout<<"enter: ";
	
	cin >>x;
	

	
		switch(x)
		{
		case 1:
			cout << "enter the radious of a circle :";
			cin >> radiousofC ;
			areaofC=PI* pow(radiousofC,2);
			cout << "the area of the circle is " << areaofC << endl;
		break;
		
		case 2:
			cout << "enter the length of the rectangle : " ;
			cin >> lengthofR;
			cout << "enter the width of the rectangle : " ;
			cin >> widthofR;
			areaofR = lengthofR * widthofR;
			cout << "the area of the rectangle is :  " << areaofR << endl;
		break;
		
		case 3:
			cout << "enter the base of the triangle : " ;
			cin >> baseofT;
			cout << "enter the height of the triangle : " ;
			cin >> heightofT;
			areaofT= (baseofT*heightofT)/2;
			cout << "The area of the triangle is : " << areaofT << endl;
		break;
		
		default:
			cout << "program quit";
		}
	
return 0;
Topic archived. No new replies allowed.