Problem with a Function

Whenever I run my program instead of doing the calculation, it just skips it. Also when I run my program Visual C++ doesn't give me any errors.
Here is my 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
#include <iostream>
#include <cmath>
#include <string>
#include <ctime>
#include <cstdlib>

#define PI 3.14159265;
#define BARTMAN 99.9;
using namespace std;

//Functions
double AreaOfCircle(double radius);
int volume(int length, int width, int heighth);
void hello();
void stock();

//Main
int main(){
    cout << "A - Option 1\nB - Option 2\nC - Option 3" << endl;
    char input;
    cin >> input;
	int ln20;
	if(input == 'A' || input == 'a'){...}
		}
	}
	else if(input == 'B' || input == 'b'){...}

	else if(input == 'C' || input == 'c'){
		double AreaOfCircle(20);
	}

	//End//
	cout << "Press <Enter> to quit";
	cin.get();
	cin.get();
    return 0;
}


..............................................

1
2
3
4
5
6
//Area Function//
double AreaOfCircle(double radius){
	double result;
	result = radius * 3.14159265 * 3.14159265;
	return result;
}
You aren't actually calling the function. On line 29 you are declaring a variable of type double called AreaOfCircle. I'm not really sure what the '(20)' is doing in this context - I'm kind of surprised that it compiles.

To call the function, remove the 'double' on line 29. Leading the line with a type name makes that line a variable declaration. But just calling it won't do anything for you because you aren't capturing the return value and doing anything with it. So you need to declare a double value for the return value of the function, assign the return value of the function to it, and then output the return value.

Also - your formula for the area of a circle is incorrect.
Topic archived. No new replies allowed.