Missed a few classes, need slight assistance with homework

As the title suggest, I need ASSISTANCE with my 4-part homework. I am only going to ask for ASSISTANCE for the 1st part, then I should be able to work my way...

Write a 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. Use the following formula:

area = πr2

Use 3.14159 for π and the radius of the circle for r. If the user enters 2, the program should ask for the length and width of the rectangle and then display the rectangle's area. Use the following formula:

area = length * width



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
#include <iostream>

using namespace std;

int main()
{
	cout << "Geometry Calculator" << endl;
	cout << " " << 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;
	cout << " " << endl;
	cout << "Enter your choice (1-4)" << endl;

	double n1 = 1, n2 = 2, n3 = 3, n4 = 4;

	if (cin >> 1)

	cout << "You have choosen to calculate the area of a circle" << endl;
	cout << "Please enter the radius of the circle: ";
	cin >> rad;

	double PI = 3.14159, areac = PI * rad * rad;

	cout << "The area of the circle is: " << areac << endl;


Thanks all.
1
2
3
4
5
6
7
8
9
10
11
void display_options()
{
    cout << "Geometry Calculator" << endl
           << " " << endl
           << "1. Calculate the Area of a Circle" << endl
           << "2. Calculate the Area of a Rectangle" << endl
           << "3. Calculate the Area of a Triangle" << endl
           << "4. Quit" << endl
           << " " << endl
           << "Enter your choice (1-4)" << endl;
}


1
2
3
4
5
6
7
8
9
int get_option()
{
    int n = 0;
    display_options();
    for ( cin >> n; n < 1 || n > 4; cin >> n )
        display_options();
    
    return n;    
}


1
2
3
4
5
6
7
8
9
10
// in main
// while(1) <-- loop maybe?
switch (get_option())
{
    case 1:
        // handle area of circle calculation
        break;

    case ...
}
Topic archived. No new replies allowed.