ive been slaving over this code and i would appreciate if you could help me see the errors that are in this program.
this is a program that i have made with functions and switch statements
the goal is to make a program that will be a 'geometry calculator' and calculate the area for 3 diff geometric shapes. at the end the program should loop asking if i want to do more
this is my completed code
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
// Function declarations
char menu();
void circle();
void rectangle();
void triangle();
void quit();
// Main function
int main( int argc, char *argv[] )
{
//Declaration of Variables.
double circleArea, rectangleArea, triangleArea,
length, width, height, base, radius;
char choice;
const double PI = 3.14159;
bool loop = true;
while( loop )
{
choice = menu();
switch (choice)
{
case '1':
circle();
break;
case '2':
rectangle();
case '3':
triangle();
case '4':
loop = false;
break;
}
}
return 0;
}
//************************
//FUNCTIONS *
//************************
char menu()
{
char temp;
cout << "\tGeometry Calculator" << endl << endl;
cout << setw(30) << "1. Calculate the Area of a [C]ircle" << endl;
cout << setw(30) << "2. Calculate the Area of a [R]ectangle" << endl;
cout << setw(30) << "3. Calculate the Area of a [T]riangle" << endl;
cout << "4. [Q]uit" << endl;
cout << setw(10) << "Enter your choice (1-4)\n";
cin >> temp;
return temp;
}
void circle()
{
double circleArea, rectangleArea, triangleArea,
length, width, height, base, radius;
char choice;
const double PI = 3.14159;
switch (choice)
{
case 'C':
case 'c':
case '1':
cout << "Enter the radius of the circle: ";
cin >> radius;
if (radius < 0)
{
cout << "Number must be greater than 0. Try again" << endl;
}
else
{
circleArea = PI * pow(radius, 2);
cout << "The area of the circle is: " << circleArea;
}
cout << endl;
break;
}
}
void rectangle()
(
double circleArea, rectangleArea, triangleArea,
length, width, height, base, radius;
char choice;
const double PI = 3.14159;
switch (choice)
{
case 'R':
case 'r':
case '2':
cout << "Enter the length and width of the rectangle: ";
cin >> length >> width;
if (length < 0 || width < 0)
{
cout << "Number must be greater than 0. Try again" << endl;
}
else
{
rectangleArea = length * width;
cout << "The area of the rectangle is: " << rectangleArea;
}
cout << endl;
break;
}
}
void triangle()
{
double circleArea, rectangleArea, triangleArea,
length, width, height, base, radius;
char choice;
const double PI = 3.14159;
switch(choice)
{
case 'T':
case 't':
case '3':
cout << "Enter the base and height of the triangle: ";
cin >> base >> height;
if (base < 0 || height < 0)
{
cout << "Number must be greater than 0. Try again" << endl;
}
else
{
triangleArea = base * height * .5;
cout << "The area of the triangle is: " << triangleArea;
}
cout << endl;
break;
}
}
void (quit)
{
switch (choice)
{
case 'Q':
case 'q':
case '4':
cout << "End of Program" << endl;
cout << "Have a Great Day!" << endl;
cout << endl;
break;
}
}
the compiler for some reasons comes up with 14 errors:
(19) : warning C4101: 'length' : unreferenced local variable
(18) : warning C4101: 'triangleArea' : unreferenced local variable
19) : warning C4101: 'base' : unreferenced local variable
18) : warning C4101: 'circleArea' : unreferenced local variable
(19) : warning C4101: 'radius' : unreferenced local variable
(19) : warning C4101: 'height' : unreferenced local variable
(19) : warning C4101: 'width' : unreferenced local variable
(18) : warning C4101: 'rectangleArea' : unreferenced local variable
(67) : warning C4101: 'length' : unreferenced local variable
(66) : warning C4101: 'triangleArea' : unreferenced local variable
(67) : warning C4101: 'base' : unreferenced local variable
(67) : warning C4101: 'height' : unreferenced local variable
(67) : warning C4101: 'width' : unreferenced local variable
(66) : warning C4101: 'rectangleArea' : unreferenced local variable
(100) : error C2061: syntax error : identifier 'rectangleArea'
(101) : error C2143: syntax error : missing ')' before ';'
(101) : error C2091: function returns function
(101) : error C2556: 'void (__cdecl *rectangle(void))(double)' : overloaded function differs only by return type from 'void rectangle(void)'
(9) : see declaration of 'rectangle'
(101) : error C2373: 'rectangle' : redefinition; different type modifiers
(9) : see declaration of 'rectangle'
(105) : error C2059: syntax error : 'switch'
(106) : error C2143: syntax error : missing ';' before '{'
(106) : error C2447: '{' : missing function header (old-style formal list?)
(130) : error C2059: syntax error : '}'
(130) : error C2143: syntax error : missing ';' before '}'
(130) : error C2059: syntax error : '}'
(133) : error C2143: syntax error : missing ';' before '{'
(133) : error C2447: '{' : missing function header (old-style formal list?)
(167) : error C2470: 'quit' : looks like a function definition, but there is no parameter list; skipping apparent body