Need reference with Geometric Calculator-Using Functions

Hello, I'm having a little issue with my program, the assignment is to create a Geometric Calculator using Functions. I tried doing function "void menu" but can't get it to work, I know it's a very little error I'm not spotting in the program correctly tried tracing but couldn't find the issue. Trying to do a very simple program done this before but with no use of functions. Any help will be highly appreciated!!! Thank you!!!!

#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
void Menu(); //Prototype

int rectangle_area, radius, area,repeat, width, length, height;
float circle_area, triangle_area;
const double PI = 3.14;
int main()
{

cout << "Enter 1 for the radius circle." << endl;
cout << "Enter 2 for the width of the rectangle." << endl;
cout << "Enter 3 for the length of the triangle." << endl;
cout << "Enter 4 for the program to quit." <<endl;
}
void Menu()
{
if (1==1)
{
cout << "Choose Your option: ";

cin >> area;
cout << endl;
switch (area)
{
case 1:
cout << "Enter the radius of a circle: " << endl;
cin >> radius;
cout << " Enter the area of a circle: " << endl;
circle_area= PI * radius * radius;
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 rectangle: " << 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;
cout << "program quit" << endl;
break;

case 4:
cout << "-☢️WARNING!WARNING!☢️-Command Activated\nProgram Closed📴" << endl;

}
}
}
This is your main function, the starting point of your program:
1
2
3
4
5
6
7
int main()
{
    cout << "Enter 1 for the radius circle." << endl;
    cout << "Enter 2 for the width of the rectangle." << endl;
    cout << "Enter 3 for the length of the triangle." << endl;
    cout << "Enter 4 for the program to quit." <<endl;
}


If you want to call Menu, you have to call it through the main function.

Also,
1
2
3
4
5
void Menu()
{
    if (1==1) /// why?
    {
        // ... 
void Menu()
{
if (1==1) /// why?
{
// ...
The if statement was when I was starting to use If's again thought it was gonna do an effect in the program for the menu at first. I removed it from the program it's working great!

"If you want to call Menu, you have to call it through the main function.
" Thank you it helped me figure out what I wasn't viewing throughout my tracing.

- Thank you for the 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
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;
void Menu(); //Prototype 

int radius, area,repeat, width, length, height;
float circle_area, rectangle_area, triangle_area;
const double PI = 3.14;
int main()
{

cout << "Enter 1 for the radius circle." << endl;
cout << "Enter 2 for the width of the rectangle." << endl;
cout << "Enter 3 for the length of the triangle." << endl;
cout << "Enter 4 for the program to quit." <<endl;
Menu();
return 0;
}
void Menu()
{
cout << "Choose Your option: ";

cin >> area;
cout << endl;
switch (area)
{
case 1:
cout << "Enter the radius of a circle: " << endl;
cin >> radius;
cout << " Enter the area of a circle: " << endl;
circle_area= PI * radius * radius;
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 rectangle: " << endl;
rectangle_area = width*length;
cout << "Rectangular Area: " << rectangle_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;
cout << "program quit" << endl;
break;

case 4:
cout << "User selected to exit." << endl << "Program Closed.📴" << endl;

}
}

Last edited on
Topic archived. No new replies allowed.