PDA

View Full Version : need another set of eyes for this..



rozzyroz
10-02-2007, 01:01 PM
i am in a class for basic c programming, and am having a problem finding out what i missed here. all was good till i added the last function (usable) and the code to go with it (highlighted red). can anyone see what mistake i have?

thanks!

#include <stdio.h>
#include <math.h>

float LxW (int, int);
float circle (int);
float usable (float, float, float);

/************************************************** *****************************
this is where the user will enter in the total area of the land.
************************************************** *****************************/
main()

{
int length, width, length2, width2, radius;
float area, area2, area3, land;

printf ("Enter in the length of the property--->");
fflush (stdin);
scanf ("&#37;d", &length);

printf ("enter in the width of the property--->");
fflush (stdin);
scanf ("%d", &width);

area = LxW (length, width);

printf ("The total area of the property is--->%4.2f", area);

/************************************************** *****************************
this is where the user will enter in the area of the house.
************************************************** *****************************/

printf ("\n\nEnter in the length of the structure--->");
fflush (stdin);
scanf ("%d", &length2);

printf ("enter in the width of the structure--->");
fflush (stdin);
scanf ("%d", &width2);

area2 = LxW (length2,width2);

printf ("the total area of the structure is--->%4.2f", area2);

/************************************************** *****************************
this bit of code will determine the area of a round pool.
************************************************** *****************************/

printf ("\n\nEnter in the radius of the pool--->");
fflush (stdin);
scanf ("%d", &radius);

area3 = circle(radius);

printf ("the total area of the pool is--->%4.2f", area3);

/************************************************** *****************************
this determines the total usable portion of the land minus the pool and
building.
************************************************** *****************************/

land = usable(area,area2,area3);

printf ("the total usable area of the land is--->%4.2f", land);
return (0);
}

/* ************************************************** ***************************
functions.
************************************************** *****************************/

float LxW (l, w)
{
float area;
area = l * w;
return (area);
}

float circle (radius)
{
float area;
float answer;
answer = pow (radius,2);
area = answer * 3.14159265359;
return (area);
}

float usable (area, area2, area3)
{
float land;
land = (area-area2)-area3;
return (land);
}

rozzyroz
10-02-2007, 05:51 PM
not sure if it makes a difference, but we have to use the borland 4.5 compiler.

it comes up with the following in the message box (error box) when i try to run.


Compiling AREA.CPP:
Warning AREA.CPP 83: Style of function definition is now obsolete
Warning AREA.CPP 90: Style of function definition is now obsolete
Warning AREA.CPP 99: Style of function definition is now obsolete
Linking area.exe:
Linker Warning: No module definition file specified: using defaults
Linker Error: Undefined symbol usable(float,float,float) in module AREA.CPP

sergers
10-02-2007, 08:19 PM
what lines correspond to those line numbers in those warnings?

I dont know why, but I can tell you the fix... or atleast the fix that makes it compile with gcc 4.1.2 (i dont have the borland compiler)


float usable (float area, float area2, float area3)
{
float land;
land = (area-area2)-area3;
return (land);
}

rozzyroz
10-03-2007, 05:46 AM
that did it! :up: you rock btw.

when i would click on the warnings, they wouldnt reference any line. confused me... almost as much as why the code you came up with works, when my code didnt...

ill have to figure that one out.

thanks a bunch!:clap:

tobe22
10-16-2007, 02:11 PM
Compiling AREA.CPP:
Warning AREA.CPP 83: Style of function definition is now obsolete
Warning AREA.CPP 90: Style of function definition is now obsolete
Warning AREA.CPP 99: Style of function definition is now obsolete
Linking area.exe:
Linker Warning: No module definition file specified: using defaults
Linker Error: Undefined symbol usable(float,float,float) in module AREA.CPP

its just saying ur using old conventions; switch to the new hotness =) declare the type for parameters and return values -- technically, even main() needs a return type (and void is a type as well):


//same as "int main(void)"
//a func with a void parameter returning an integer
int main()
{

...
return 0;}

so for the rest of your functions, you also have to do as sergers did, declare a type for all your parameters, even if you already have them prototyped:


float LxW (float l, float w)
{

float area;
area = l * w;
return (area);}


float circle (float radius)
{

float area;
float answer;
answer = pow (radius,2);
area = answer * 3.14159265359;
return (area);}

Have fun!