Geometry Code HELP

I am a beginner to programming and taking a c++ class at my local college as part of a career/major change.

I've worked out most of this code for an assignment online but I'm missing key elements in the execution that woefully will not be accepted by visual studio. Any help in troubleshooting this script would be much appreciated. I think I have been staring at this for too long. Thanks!

Respectfully,
Armygun087


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
145
146
147
148
149
150
151
152
153
154
  #include <iostream>
#include <iomanip>

using namespace std;

int displayMenu();
double calcAreaCircle(double radius);
double calcAreaRect(double length, double width);
double calcAreaTriangle(double base, double height);

const double Pi = 3.14159265359;

int main()
{
	int choice;
	double radius{}, width{}, length{}, base{}, height{};
	double menu;
	choice = displayMenu();

	double circ_area;
	circ_area = calcAreaCircle(radius);

	double rect_area;
		rect_area = calcAreaRect(length, width);

	double tri_area;
		tri_area = calcAreaTriangle(base, height);

	switch (choice)
	{
	case 1:
	{
		cout << "Please enter the Radius:" << endl;
		cin >> radius;
	}
	break;

	case 2:
	{
		cout << "Please enter the Length:" << endl;
		cin >> length;
		cout << endl;

		cout << "Please enter the width:" << endl;
		cin >> width;
		cout << endl;
	}
	break;

	case 3:
	{
		cout << "Please enter the Base:" << endl;
		cin >> base;
		cout << endl;

		cout << "Please enter the Height:" << endl;
		cin >> height;
		cout << endl;

	}

	break;

	case 4:

		cout << "Thank you for using the geometry calculator, Bye! " << endl;
		system ("pause");
		break;

	}

}

int displayMenu()
{
	int choice;

	cout << "Geometry Calculator" << 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;
	cin >> choice;


	while (choice < 1 || choice > 4)
	{
		cout << "Invalid selection. Enter 1, 2, 3, or 4: ";
		cin >> choice;
	}
	return choice;

}


double calcAreaCircle(double radius)
{

	double circ_area = Pi * radius*radius;

	if (radius > 0.0)
	{
		cout << "The area of the circle " << radius << " is: " << circ_area << endl;
		system("pause");
		return (0);
	}
	else
	{
		cout << "You did not enter a valid number" << endl;
		cout << "The program will now restart" << endl;
		system("pause");
		return circ_area;
	}
}


double calcAreaRect(double width, double length)
{
	double rect_area = length * width;

		if (length > 0.0, width > 0.0)
		{
			cout << "The Area for the Rectangle is: " << rect_area << endl;
			system("pause");
			return 0;
		}

		else
		{
			cout << "You did not enter valid numbers." << endl;
			cout << "The program will now restart." << endl;
			system("pause");
			return rect_area;
		}
}

double calcAreaTriangle(double base, double height)
{
	double tri_area = base * height;


	if (base > 0.0, height > 0.0)
		{
			tri_area = 0.5 * base * height;
		}
		else
		{
			cout << "You did not enter a valid number." << endl;
			cout << "The program will now restart." << endl;
			system("pause");
			return tri_area;
		}

}


What I am getting though is:

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
1
You did not enter a valid number
The program will now restart
Press any key to continue . . .

None of the values seem to register properly. -_- inputting 1-4 yields the same results, unfortunately.

Okay, I've been pouring over this for some time now and am hoping someone can help me fix this so it'll work. I have taken apart most if not all the code, shortened, and removed functions that as a base were making this too complicated to keep. I've gone back to one of my previous projects and hope that this may expedite things. Here's what I have now, but I am getting new error codes. Help is VERY much appreciated. Thank you.

P.S. I know that my established values just below int main may seem redundant but I am beginning to panic. so please excuse, and I apologize for any rash or obvious mistakes where they are.

Respectfully,
Armygun087

-from line one:

"Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "double __cdecl calcAreaCircle(double,double)" (?calcAreaCircle@@YANNN@Z) referenced in function_main 1 "

"Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "double __cdecl calcAreaRect(double,double)" (?calcAreaRect@@YANNN@Z) referenced in function _main 1"

"Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol "double __cdecl calcAreaTriangle(double,double)" (?calcAreaTriangle@@YANNN@Z) referenced in function _main 1"

"Severity Code Description Project File Line Suppression State
Error LNK1120 3 unresolved externals 1

- Line 57
"Severity Code Description Project File Line Suppression State
Warning C4551 function call missing argument list 57

-Line 68
"Severity Code Description Project File Line Suppression State
Warning C4551 function call missing argument list 68

And my new code:

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
#include <iostream>
#include <math.h>

using namespace std;
int main()
{
	int area;
	double radius;
	double width;
	double length;
	double height;
	double calcAreaCircle(const double PI, double radius);
	double calcAreaRect(double length, double width);
	double calcAreaTriangle(double base, double height);
	const double PI = 3.14159265359;

	// Menu //

	cout << "Enter 1 to calculate the area of a circle" << endl;
	cout << "Enter 2 to calculate the area of a rectangle" << endl;
	cout << "Enter 3 to calculate the area of a triangle" << endl;
	cout << "Enter 4 for the program to quit" << endl << "\n";


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

		switch (area)
		{
		case 1:
			cout << "Enter the radius of the circle.\n";
			cin >> radius;
			calcAreaCircle;			//Calculates the area of a cirlce //
			cout << "The area of the circle is " << calcAreaCircle << "\n";
			cout << "Choose Your option : ";
			cin >> area;
			cout << endl;

		case 2:
			cout << "Enter the width of the rectangle.\n";
			cin >> width;
			cout << "Enter the length of the rectangle.\n";
			cin >> length;
			calcAreaRect;			//Calculates the area of a rectangle //
			cout << "The area of the rectangle is " << calcAreaRect << "\n";
			cout << "Choose Your option : ";
			cin >> area;
			cout << endl;

		case 3:
			cout << "Enter the length of triangle's base.\n" << endl;
			cin >> length;
			cout << "Enter the height of the triangle.\n" << endl;
			cin >> height;
			calcAreaTriangle;		//Calculates the area of a triangle //
			cout << "The area of the triangle is " << calcAreaTriangle << "\n";
			cout << "Choose Your option : ";
			cin >> area;
			cout << endl;

		case 4:                                         //Allows user to quit the program //
			cout << "Ending program, standby to make final acknowledgement." << endl;

			system("pause");
			return 0;
		}
	}
}
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
#include <iostream>

void display_menu() ;
int get_choice() ;
void do_area_of_circle() ;
void do_area_of_rectangle() ;
void do_area_of_triangle() ;

int main()
{
    display_menu() ;

    switch( get_choice() )
    {
        case 1 : do_area_of_circle() ; break ;
        case 2 : do_area_of_rectangle() ; break ;
        case 3 : do_area_of_triangle() ; break ;
    }

    std::cout << "\nThank you for using the geometry calculator, Bye!\n" ;
}

void display_menu()
{
    std::cout << "\nGeometry Calculator\n\n"
                 "1. Calculate the Area of a Circle\n"
                 "2. Calculate the Area of a Rectangle\n"
                 "3. Calculate the Area of a Triangle\n"
                 "4. Quit\n\n" ;
}

void input_error()
{
    std::cout << "Invalid input.\n";

    // clear a possible failed state (input may have been non-numeric eg. 'abcd')
    // http://en.cppreference.com/w/cpp/io/basic_ios/clear
    std::cin.clear() ;

    // http://en.cppreference.com/w/cpp/io/basic_istream/ignore
    std::cin.ignore( 1000, '\n' ) ; // throw the bad input away
}

int get_choice()
{
    std::cout << "Enter 1, 2, 3, or 4: " ;

    int choice ;
    if( std::cin >> choice && choice > 0 && choice < 5 ) return choice ;

    input_error() ;
    return get_choice() ;
}

double get_dimension( const char* prompt = "" )
{
    std::cout << prompt << " (enter a positive number): " ;

    double num ;
    if( std::cin >> num && num > 0  ) return num ;

    input_error() ;
    return get_dimension(prompt) ;
}

void do_area_of_circle()
{
    const double Pi = 3.14159265359;

    const double radius = get_dimension( "radius of the circle" ) ;
    std::cout << "area of the circle is: " << Pi*radius*radius << '\n' ;
}

void do_area_of_rectangle()
{
    const double width = get_dimension( "width of the rectangle" ) ;
    const double height = get_dimension( "height of the rectangle" ) ;
    std::cout << "area of the rectangle is: " << width*height << '\n' ;
}

void do_area_of_triangle()
{
    const double base = get_dimension( "base of the triangle" ) ;
    const double height = get_dimension( "height of the triangle" ) ;
    std::cout << "area of the triangle is: " << base*height / 2.0 << '\n' ;
}
Thank for your help, but I am restricted to using these prototypes -_-
I apologize for not including this in my OP.

1
2
3
4
int displayMenu(); //displays menu and returns validated selection
double calcAreaCircle( double radius ); //returns the area of the circle, validate input
double calcAreaRect( double length, double width ); //returns the area of a rectangle, validate input
double calcAreaTriangle( double base, double height ); //returns the area of a triangle, validate inpu 
Last edited on
Okay, I've been playing around with what you sent out. And here's what I have so far while trying to get those prototypes into it. I'm getting a lot of redefining of the formal parameters and I don't know how to fix these without removing the changes I've made to the code to suit my requirements.

Redefine requests are located as follows.

line 72-"Pi"
line 74 - "radius"
line 80 - "length"
line 81 - "width"
line 87 - "base"
and line 88 - "height"

Code as is vvvv

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

int display_menu();
int get_choice();
double calcAreaCircle(double radius);
double calcAreaRect(double length, double width);
double calcAreaTriangle(double base, double height);

int main()
{
	display_menu();

	switch (get_choice())
	{
	case 1: double calcAreaCircle(double radius); break;
	case 2: double calcAreaRect(double length, double width); break;
	case 3: double calcAreaTriangle(double base, double height); break;
	}

	std::cout << "\nThank you for using the geometry calculator, Bye!\n";

	system("pause");

}

int display_menu()
{
	std::cout << "\nGeometry Calculator\n\n"
		"1. Calculate the Area of a Circle\n"
		"2. Calculate the Area of a Rectangle\n"
		"3. Calculate the Area of a Triangle\n"
		"4. Quit\n\n";
	
}

void input_error()
{
	std::cout << "Invalid input.\n";

	// clear a possible failed state (input may have been non-numeric eg. 'abcd')
	// http://en.cppreference.com/w/cpp/io/basic_ios/clear
	std::cin.clear();

	// http://en.cppreference.com/w/cpp/io/basic_istream/ignore
	std::cin.ignore(1000, '\n'); // throw the bad input away
}

int get_choice()
{
	std::cout << "Enter 1, 2, 3, or 4: ";

	int choice;
	if (std::cin >> choice && choice > 0 && choice < 5) return choice;

	input_error();
	return get_choice();
}

double get_dimension(const char* prompt = "")
{
	std::cout << prompt << " (enter a positive number): ";

	double num;
	if (std::cin >> num && num > 0) return num;

	input_error();
	return get_dimension(prompt);
}

double calcAreaCircle(double Pi, double radius)
{
	const double Pi = 3.14159265359;

	const double radius = get_dimension("radius of the circle");
	std::cout << "area of the circle is: " << Pi * radius*radius << '\n';
}

double calcAreaRect(double length, double width)
{
	const double length = get_dimension("length of the rectangle");
	const double width = get_dimension("width of the rectangle");
	std::cout << "area of the rectangle is: " << length * width << '\n';
}

double calcAreaTriangle(double base, double height)
{
	const double base = get_dimension("base of the triangle");
	const double height = get_dimension("height of the triangle");
	std::cout << "area of the triangle is: " << base * height / 2.0 << '\n';
}


I am going to keep tinkering. Thank you.
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
#include <iostream>
#include <cmath>

int display_menu() ; //displays menu and returns validated selection

double calcAreaCircle( double radius ) ; //returns the area of the circle, validate input
double calcAreaRect( double length, double width ) ; //returns the area of a rectangle, validate input
double calcAreaTriangle( double base, double height ) ; //returns the area of a triangle, validate inpu

double get_dimension( const char* prompt = "" ) ; // get a non-negative value from stdin

int main()
{
    switch( display_menu() )
    {
        case 1 :
        {
            const double radius = get_dimension( "radius of the circle" ) ;
            std::cout << "area of the circle is: " << calcAreaCircle(radius) << '\n' ;
            break ;
        }

        case 2 :
        {
            const double width = get_dimension( "width of the rectangle" ) ;
            const double height = get_dimension( "height of the rectangle" ) ;
            std::cout << "area of the rectangle is: " << calcAreaRect(width,height) << '\n' ;
            break ;
        }

        case 3 :
        {
            const double base = get_dimension( "base of the triangle" ) ;
            const double height = get_dimension( "height of the triangle" ) ;
            std::cout << "area of the triangle is: " << calcAreaTriangle(base,height) << '\n' ;
        }
    }

    std::cout << "\nThank you for using the geometry calculator, Bye!\n" ;
}

double calcAreaCircle( double radius ) // returns NaN on invalid input
{
    const double Pi = 3.14159265359;
    // http://en.cppreference.com/w/cpp/numeric/math/nan
    // https://en.wikipedia.org/wiki/NaN
    return radius >= 0 ? Pi*radius*radius : std::nan("") ;
}

double calcAreaRect( double length, double width ) // returns NaN on invalid input
{ return length >= 0 && width >= 0 ? length*width : std::nan("") ; }

double calcAreaTriangle( double base, double height ) // returns NaN on invalid input
{ return base >= 0 && height >= 0 ? base*height / 2.0 : std::nan("") ; }

void input_error()
{
    std::cout << "Invalid input.\n";

    // clear a possible failed state (input may have been non-numeric eg. 'abcd')
    // http://en.cppreference.com/w/cpp/io/basic_ios/clear
    std::cin.clear() ;

    // http://en.cppreference.com/w/cpp/io/basic_istream/ignore
    std::cin.ignore( 1000, '\n' ) ; // throw the bad input away
}

int get_choice()
{
    std::cout << "Enter 1, 2, 3, or 4: " ;

    int choice ;
    if( std::cin >> choice && choice > 0 && choice < 5 ) return choice ;

    input_error() ;
    return get_choice() ;
}

int display_menu()
{
    std::cout << "\nGeometry Calculator\n\n"
                 "1. Calculate the Area of a Circle\n"
                 "2. Calculate the Area of a Rectangle\n"
                 "3. Calculate the Area of a Triangle\n"
                 "4. Quit\n\n" ;

    return get_choice() ; // returns validated selection
}

double get_dimension( const char* prompt )
{
    std::cout << prompt << " (enter a positive number): " ;

    double num ;
    if( std::cin >> num && num >= 0  ) return num ;

    input_error() ;
    return get_dimension(prompt) ;
}
um....errors in files I've never made.

145 errors total, keeping MainCode from running properly.

File name

- sal.h -
- crtdbg.h -
- stddef.h -
- stdlib.h -

Among many others all located at this address.

" C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.12.25827\include "

Very confused.....

Respectfully,
Armygun087


Edit: NVM I figured out what was wrong. Thanks again JLBorges
Last edited on
Topic archived. No new replies allowed.