Geometry Calculator

My exercise asks me to write a program (geometry.cpp) that displays the following menu:
Geometry Calculator:
1. Calculate the area of a circle
2. calculate the area of a rectangular
3. calculate the area of a triangle
4. quit

Enter your choice (1-4)

-if the user enters 1, then the program should ask for the radius of the circle and then should display the area. use 3.14159 for PI.
- if the user enters 2, then the program should ask for the width and length of the rectangle and then should display the area.
- if the user enter 3, then the program should ask for the length of the triangle base and its height and then should display the area.
- if the user enters 4, then the program should quit.

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
#include <iostream>
#include <math.h>
#include <iomanip>
#include "stdafx.h"
using namespace std;
main()
		{
	    int a, b, c, circle_area, s, rectangle_area, triangle_area, radious, quit, area, width, length, height;
		const double PI = 3.14;
		cout << "enter 1 for the radious circle" << radious << "enter the area of a circle" << circle_area << endl;
		cout << "Enter 2 for the width of the rectangle" << width <<"enter the length of the rectangle"<< length << "enter the area of the rectangular"<< rectangle_area <<  endl; 
		cout << "Enter 3 for the lenght of the triangle" << length<< " enter the area of a triangle" << triangle_area << endl;
		cout << "Enter 4 for the program to quit" << quit <<endl;
		switch (area)
		{
		case 1:
			cout << "enter the radious of a circle\n";
			cin >> radious;
		cout << " enter the area of a circle. \n";
		cin >> circle_area;
		circle_area= PI * radious * radious;
		cout << "area of the circle is" << circle_area << endl;
		break;
		
		case 2:
		cout << "enter the width of a rectangle" << width << endl;
		cin >> width;
		cout << "enter the length of the rectangle" << length << endl;
		cin >> length;
		cout << "enter the area of the rectangl" << area << endl;
		cin >> rectangle_area;
		rectangle_area = a * b;
		cout << "Rectangular Area =" << triangle_area << endl;
		break;

		case 3:
		cout << "enter the length of a triangle" << length << endl;
		cin >> length;
		cout << "enter the height of a triangle" << height << endl;
		cin >> height;
		s = (a + b + c) / 2;
		triangle_area = sqrt(s*(s - a)*(s - b)*(s - c));

		cout << "Triangle Area=" << triangle_area << endl;
		cin >> triangle_area;
		break;

		case 4:
		cout << "program quit" << quit << endl;
		cin >> quit;
		return 0;
		}

when I debug, it says cin, cout, int hasn't been initialized. I'm not what I'm not sure wats wrong with my code.
I appreciate your help!
 
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
#include <iostream>
#include <math.h>
#include <iomanip>

using namespace std;
int main()
{
    int rectangle_area, radious, area, width, length, height;
    float circle_area, triangle_area;
    const double PI = 3.14;
    cout << "enter 1 for the radious circle" << endl;
    cout << "Enter 2 for the width of the rectangle" <<  endl;
    cout << "Enter 3 for the lenght of the triangle" << endl;
    cout << "Enter 4 for the program to quit" <<endl;


    while (1==1)
    {
        cout << "Choose Your option : ";
        cin >> area;
        cout << endl;

        switch (area)
		{
            case 1:
                cout << "enter the radious of a circle\n";
                cin >> radious;
                cout << " enter the area of a circle. \n";
                circle_area= PI * radious * radious;
                cout << "area of the circle is " << circle_area << endl;
            break;

            case 2:
                cout << "enter the width of a rectangle"<< endl;
                cin >> width;
                cout << "enter the length of the rectangle" << endl;
                cin >> length;
                cout << "enter the area of the rectangl"  << endl;
                rectangle_area = width*length;
                cout << "Rectangular Area =" << triangle_area << endl;
            break;

            case 3:
                cout << "enter the length of a triangle" << endl;
                cin >> length;
                cout << "enter the height of a triangle" << endl;
                cin >> height;

                triangle_area = length * height /2;

                cout << "Triangle Area=" << triangle_area << endl;

            break;

            case 4:
                cout << "program quit" << endl;
                return 0;
		}
    }

}


Area of rectangle = length * base;
area of triangle = height * base /2;

"cout" will cause the console output value, and i notice you tried to output some variables without giving them a value first, you will end up getting random number.

and "cin >> vars" will allow user to input value into vars, after u conpute those area, u don need to cin>>area, u will overwrite the answer.

and if u declare variable with int, the answer will get round up to whole number when it has remainder or decimal... use float or double instead.

I add a while infinite while loop by giving a 1==1 statement which is always true, but if user input unexpected character into the program, something funny will happen...
@selenium


what are the functions of the:

#include<math.h>
and #include<iomanip>

im a newbie... :)

thanks...
to tell the compiler to include the 2 library.

if u include cmath, u can access to function like cos(),sin().... almost all mathematical function

if u include iomanip u can use function which can manipulate how the things shown up in the console.

and actually in khatereh's code those 2 library is not used.
now i know.. thanks a lot.. selenium.. :)
Topic archived. No new replies allowed.