Hello Armygun087
When I started running your program to see what happens is when I noticed the bigger problems.
At the beginning of the main file you use the line
using namespace std;
. It is best to learn not to use this line as it
WILL get you in trouble some day.
If you are going to use PI as a double you should make use of more than 5 decimal places. You have up to 20 places that you can use.
In main:
You start with defining your variables witch should be initialized at the same time. followed by a call to "displayMenu" which returns a value. so far so good.
Next you define three variables and call three functions passing variables the have no usable (garbage) value, as in your program original code, or have a value of zero if you initialize your variables. This is done before you get to the switch statement where you actually enter a value for the variables that are passed to the functions. I would call it poor program flow.
Line 18 should be followed by line 29 and the "switch" could look something like this:
1 2 3 4 5 6 7 8 9 10
|
switch (choice)
{
case 1:
cout << "Please enter the Radius:" << endl;
cin >> radius;
circ_area = calcAreaCircle(radius);
break;
default:
break;
}
|
witch makes more sense to enter a value into the variable before you call the function. Notice the lack of {}s in the case statement. They are OK if you want to use them, but they are not needed. Everything between the ":" and the ";" at the end of the break statement is considered part of the case statement.
The "displayMenu()" function works. I do not see any problem with this function.
The next three functions kind of work although I am not sure if I understand what you are trying to do with these functions. In all three functions if true you return zero to a variable in main that is never used. if false you return the answer, you consider to be wrong, to the same variable that is never used. The chances are that only the else part will be reached.
In the second and third functions the if statements at lines 122 and 143 are wrong. The ',' operator does not work the way you are thinking. What you need here is the logical && or logical || in the if condition
if (length > 0.0 && width > 0.0);
. The ";" at the end is not needed here. It shortens the if statement to just this line and everything after this that you want with the "if" is considered separate code. The logical and (&&) is the best choice here because you need both sides to be true.
This is what I have found so far. I still need to do the rearranging I talked about to see if there is anything else.
Hope that helps,
Andy