help with C program

tmh88tmh88 Pittsburgh / Athens, OH
edited January 2007 in Internet & Media
Hey guys I need a little bit of help with a C program. Its a simple program that asks for the radius, and calculates the area of a cirlce. I have lab tomorrow for the class and my professor already told us the assignment so I just want to get it working so I can finish with the lab quickly. Anyway heres what I have. I'd appreciate it if someone would run this in a compiler for me to check and see if it works (i dont have one installed on this computer).

# include <stdio.h>
# define PI 3.14
int main (void) {
double radius, area;
printf ("Enter size of the radius");
scanf "%1f", & radius";
area = radius * radius * PI;
printf ("The area equals", area);
return(0);
}


I'm new to C so let me know if you see something obvious, or if it can be made simpler.

Comments

  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    your second printf won't do what you want it to do.

    also, you can download cygwin (and make sure you get gcc) so you can have a c-compiler.

    and, use [php]
    
    [/php] tags to post code.                        
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited January 2007
    Ok I went back through and changed it, should it work properly?
    # include <stdio.h>
    # define PI 3.14159
    
    int main (void)
    double area;
    double radius;
    
    printf ("Enter radius length> ");
    scanf ("%1f", &radius);
    area = PI * radius * radius;
    printf ("The area is %1f", area);
    
    return (0);
    }
    

    I asked my professor and said that we will be using the gnu compiler.
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    if you download cygwin, you have the option to install gcc (gnu c-compiler). And then you can test your code from now on.

    edit:

    and you're missing an open curly bracket after main()
  • edited January 2007
    just a hint, #include expects a filename. and no, I this isn't going to output what you want at all.
  • KyleKyle Lafayette, LA New
    edited January 2007
    lightnin is right. You need to specify a file with your "#include" statement (most likely stdio.h)

    The only thing I see wrong with your code is the scanf statement. It should use %lf, not %1f. I guess you looked at some example code and it was hard to distinguish between a lowercase L and a one?
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited January 2007
    i'm pretty sure the filename after #include was parsed out by the forums.
  • tmh88tmh88 Pittsburgh / Athens, OH
    edited January 2007
    yea i forgot to put
    <stdio.h>
    
    up there after #include. anyway i got the program to run fine.
  • edited January 2007
    >i'm pretty sure the filename after #include was parsed out by the forums.

    heh, oops...
Sign In or Register to comment.