*sigh* It sounds like you are having difficulty with simple code structure. Are you using a book to learn or a website? Either way, reading the early chapters on general program structure will go a long way to help you, plus the section on basic functions and especially how to call them, and how to use their return values.
Just because you declared the functions doesn't mean they'll automatically work. You have to specifically call each one in the proper way with the proper arguments (if any) and assign the return values (again, if any).
Also, just browsing over some of your functions says they are improperly written. To note:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void Step7();
{
int option = 7;
double radius;
double pi;
double AreaofaCircle;
pi = 3.1416;
AreaofaCircle = radius * radius * pi;
while (option !=99)
{
if(option == 7)
{
cout << "Enter Radius of the Circle " << endl;
cin >> radius;
cout << "The Area is "<< AreaofaCircle << endl;
}
else
if(option == 8);
}
| |
First, int option = 7. Why is this here? what do you use it for? The test in the IF loop later is completely useless since you have already set option to 7, it HAS to be 7 any time you call this function. There nothing between the assignment and the IF loop to change it.
Second, you declare double radius and double pi, but don't initialize them. Then you try to use them in a statement. That will not work at all. Variables must be initialized before you do anything to them (at least at run time if not during compiling). You DO input the radius later, but pi is still undefined. What you could do is declare pi as a const double at the very beginning of the code (before main() ) that way you don't have to declare or initialize it anywhere else. Also, since you are relying on user input for radius you must put the AreaofaCircle = radius * radius * pi AFTER the input, otherwise how is the program to know what the value of radius is? Edit: OOPS, I just saw that you did indeed initialize PI. My bad. :) You still need to actual calculation statement to after the con >> radius line though so that radius contains the inputted value BEFORE the calculation.
And lastly, like I said in the beginning, the while and if loops are completely unnecessary. I'm assuming what you are testing here is for the exit condition of choice = 99. That testing should be done before you even try to call any of the functions, not in each function itself. Additionally, you don't even use the right variable for it. While it COULD work with a 2nd variable, you'd have to pass choice to the function as an argument which would look like
void Step8 (int option)
in your function declaration. Then your function call to step 8 would be
Step8(choice)
. This would pass the value contained in CHOICE to the Step8() and it would be assigned to OPTION. But, like I said, this probably won't do what you hope it would (which is exit your program....) A better option would be to use a switch with one of the cases being
case 99 : return 0;
(at least, I think that would terminate the program... if not someone else will prolly correct me. You might have to use a break to get out of the switch first though... hmmm... don't think so though)
Anyway, like I said, there are some incredibly fundamental errors in this code that really warrant a complete reread of basic C++ programming structure. I'm actually really confused how you got to writing functions already. At least, the book I'm using hasn't even really introduced functions yet, though it does use a few in some examples and I'm familiar with them from previous attempts at learning languages (mostly scripting stuff, but I've tried C before and bleh...)