Need Help

I am having trouble with this code. We are supposed to write functions to make the main work. We were given the main. I don't understand what I am doing wrong. If someone could steer me in the right direction please.


#include<iostream>
using namespace std;
double getRadius(double);
double findArea(double);
double findCircumference(double);
int main()
{

double radius; //the radius of the circle
double area; //the area of the circle
double circumference; //the circumference of the circle


//get the value of the radius from the user
radius = getRadius();

//determine the area and circumference
area = findArea(radius);
circumference = findCircumference(radius);

//output the results
cout << "A circle of radius " << radius << " has an area of: " << area <<endl;
cout << "and a circumference of: "<< circumference << endl;

system("pause");
return 0;
}
double getRadius(double)
{
double i;
cout<<"Please enter the radius of the circle."<<endl;
cin>>i;
return i;
}

double findArea(double radius)
{
double i2;
i2=3.14159*radius*radius;
return i2;
}

double findCircumference(double radius)
{
double i3;
i3=2*3.14159*radius;
return i3;
}

Here is the error codes I am getting.

1>------ Build started: Project: Lab_6, Configuration: Debug Win32 ------
1> lab6.cpp
1>c:\users\nate\documents\visual studio 2012\projects\lab_6\lab_6\lab6.cpp(19): error C2660: 'getRadius' : function does not take 0 arguments
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


Thanks for any help you can give me.
A few things... (see comments in code)

First, "system pause" requires the "cstdlib" library.

Second, your prototypes are correct, but you must also include the arguments when calling a function. You need to tell the function what variables it is dealing with when using the function.
When calling getRadius(), you must tell the function that it is dealing with the variable "i", so we put:
radius = getRadius(i);
Since "i" is now a variable being using in main, we must also declare "double i" in main along with your other variables.

Thirdly, in your function description of getRadius, you may declare "double i" in the parameters (just like you did with all the other functions.

ALWAYS REMEMBER: Your prototype tells your function what it is going to look like and your arguments tells main what variables the function is going to be dealing with.


All these are corrected and commented in the code below.

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
#include	<iostream>
#include	<cstdlib>//include for system pause
using namespace std;

double getRadius(double);
double findArea(double);
double findCircumference(double);

int main()
{

double radius;
double area;
double circumference;
double i;//include i in main


radius = getRadius(i);//must include i as an argument


area = findArea(radius);
circumference = findCircumference(radius);


cout << "A circle of radius " << radius << " has an area of: " << area <<endl;
cout << "and a circumference of: "<< circumference << endl;

system("pause");
return 0;
}
double getRadius(double i)
{

cout<<"Please enter the radius of the circle."<<endl;
cin>>i;
return i;
}

double findArea(double radius)
{
double i2;
i2=3.14159*radius*radius;
return i2;
}

double findCircumference(double radius)
{
double i3;
i3=2*3.14159*radius;
return i3;
}
Last edited on
MrZ,

Thanks for the reply. I made the changes you said to but I am still getting an error code. It is:

1>------ Build started: Project: Lab_6, Configuration: Debug Win32 ------
1> lab6.cpp
1>c:\users\nate\documents\visual studio 2012\projects\lab_6\lab_6\lab6.cpp(20): error C4700: uninitialized local variable 'i' used
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
If your compiler does not initialize it, then change
int i;
to
int i = 0;
inside your main function.

Some compilers will compile with uninitialized variables, some will give back an error.
(My compiler did not)
Last edited on
MrZ,

That did it. Thank you very much. Now I can get on to my wifes honey do list. She thanks you too.

Nate
Topic archived. No new replies allowed.