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;
}
}
}
|