Some of those compiler warnings point to issues which need to be fixed.
C:\Users\Owner\Desktop\C++ Files\Geometric Calculator.cpp: In function 'int main()':
C:\Users\Owner\Desktop\C++ Files\Geometric Calculator.cpp:175:
warning: the address of 'int nOptionThree()' will never be NULL |
Here is the code which causes that:
173 174 175 176 177 178 179 180 181
|
case 3:
nOptionThree();
if(nOptionThree == 0)
{
system("PAUSE");
return 0;
}
else
break;
|
Function
nOptionThree()
returns an integer, but when the function is called at line 174 nothing is done with that integer. in addition at line 175, the bare name
nOptionThree
gives simply the address of the function (the location in memory where the code for the function begins). Iinstead, the code might look like this:
|
int option3 = 0; // declare an integer variable and initialise it.
|
173 174 175 176 177 178 179 180 181
|
case 3:
option3 = nOptionThree(); // call function and assign returned value to the variable
if (option3 == 0) // check the value we just stored
{
system("PAUSE");
return 0;
}
else
break;
|
Alternatively, you can call the function and check its returned value like this, without storing it:
173 174 175 176 177 178 179 180
|
case 3:
if (nOptionThree() == 0) // call function and check the value returned
{
system("PAUSE");
return 0;
}
else
break;
|
Ok, that's one problem covered. Now the next one.
C:\Users\Owner\Desktop\C++ Files\Geometric Calculator.cpp: In function 'int nOptionThree()':
C:\Users\Owner\Desktop\C++ Files\Geometric Calculator.cpp:138:
warning: control reaches end of non-void function |
Inside the body of function
nOptionThree()
, at lines 123 and 127 a value is returned. However, it may be possible to reach the closing brace of the function at line 138 without executing a
return x
, thus the function which is supposed to return an integer might not return a value after all. There should
always be some value returned, so add a statement at line 138, such as
|
return -1; // return a default value
|
I put -1 here to indicate that the function has unexpectedly reached the end without returning anything sensible. The choice is up to you, as to whether reaching the last line is a normal or abnormal situation, that's a matter of how you intend the function to work.
Other comments.
Well done for using an accurate value for pi. Though #define is more of a C idiom, in C++ it is preferred to use a constant instead:
|
const double PI = 3.1415926535897932385;
|
There's a lot of calls to
system()
which is probably better avoided, firstly is is slow and clunky, it is also generally regarded as bad practice. See
http://www.cplusplus.com/articles/j3wTURfi/
edit: at line 13 there are some global variables declared.
13 14 15
|
int nOptionSelect;
int nSecondOS;
int nThirdOS;
|
Generally that's something you should avoid. Instead, declare the variables in the function where they will be used. Communicate between functions by passing of parameters when calling the function, and by making use of the returned value.
An aim is to limit the visibility (scope) of the variable to only the part of the program where it will be needed. That reduces confusion as each function has access only to those variables it is supposed to be using, so won't mistakenly read or write something it has no right to be using.