need help getting my code to run

closed account (yTRM92yv)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
 //Audy L Sain
//Week 8 Assignment 1
//Geometry Calculator

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

const float pi = 3.14150;

//Functions
void showMenu();
void showCircle(float, float);
void showRectangle(float, float, float);
void showTriangle(float, float, float);
void showTrapezoid(float, float, float, float);
void showSphere(float, float);
 

int main()
{
int choice; //Menu choices
float area, radius, length, width, area1, base,
height, area2, height1, base1, base2,
area3, radius1, area4;

const int	Circle_Area = 1,
Rectangle_Area = 2,
Triangle_Area = 3,
Trapezoid_Area = 4,
Sphere_Area = 5,
Exit = 6;
 
do
{
showMenu();
cin >> choice;

while (!cin || choice < Circle_Area || choice > Exit)
{
cout << "Please enter a valid Number: ";
cin.clear();
cin.ignore(1000, '\n');
cin >> choice;
}
 
if (choice != Exit)
{
switch (choice)
{

case Circle_Area:
showCircle(radius, area);
break;

case Rectangle_Area:
showRectangle(length, width, area1);
break;

case Triangle_Area:
showTriangle(base, height, area2);
break;

case Trapezoid_Area:
showTrapezoid(height1, base1, base2, area3);
break;

case Sphere_Area:
showSphere(radius1, area4);
break;
}
}
 
}
while (choice != Exit);

return (0);
}

//Menu Function
void showMenu()
{
cout << "Please choose a selection" << 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. Calculate the Area of a Trapezoid" << endl
<< "5. Calculate the Area of a Sphere" << endl
<< "6. Exit" << endl << endl;
}

//Circle Function
void showCircle(float radius, float area)
{
cout << "What is the radius of the circle :";
cin >> radius;
area = pi * pow(radius, 2);
cout << "\nThe area of the circle is :" << area << endl << endl;
}

//Rectangle Function
void showRectangle(float length, float width, float area1)
{
cout << "What is the rectangle length :";
cin >> length;
cout << "\nWhat is the rectangle width :";
cin >> width;
area1 = length * width;
cout << "\nThe area of the rectangle is :" << area1 << endl << endl;
}

//Triangle Function
void showTriangle(float base, float height, float area2)
{
cout << "What is the length of the triangle's base :";
cin >> base;
cout << "\nWhat is the height of the triangle :";
cin >> height;
area2 = base * height * 0.5;
cout << "\nThe area of the triangle is :" << area2 << endl << endl;
}

//Trapezoid Function
void showTrapezoid(float height1, float base1, float base2, float area3)
{
cout << "What is the height of the trapezoid :";
cin >> height1;
cout << "\nWhat is the first base of the trapezoid :";
cin >> base1;
cout << "\nWhat is the secound base of the trapezoid :";
cin >> base2;
area3 = height1 / 2 * (base1 + base2);
cout << "\nThe area of the trapezoid is :" << area3 << endl << endl;
}

//Sphere Function
void showSphere(float radius1, float area4)
{
cout << "What is the radius of the sphere :";
cin >> radius1;
area4 = 4 * pi * pow(radius1, 2);
cout << "The area of the sphere is :" << area4 << endl << endl;
}
Last edited on
You are using some editor which is using some problematic unicode characters.

a) Switch to another editor. There are many editors suitable for programmers: Notepad++, ConText, Geany, etc...

b) remove the invalid characters manually

When this issue is fixed, the code will run.
closed account (yTRM92yv)
thanks but i found out what the problem was i had to assign all these value to zero

1
2
3
float area, radius, length, width, area1, base,
height, area2, height1, base1, base2,
area3, radius1, area4;
I'm pretty sure that the code was running even without assigning variables to zero, which means that your original question was not stated correctly.

You should have said that the program is not working correctly, not that it is not running.
closed account (yTRM92yv)
sorry. I'm new to all this, I just started writing code like two months ago
Topic archived. No new replies allowed.