Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

new to C and programming please help

Name: Anonymous 2011-11-20 3:18

I am doing this example from the book C all-in-one desk reference for dummies, the proper answer is suppose to be 34.64
but my answer is always 0.00 .
my os is linux mint 9, here is the code:

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

#define RAD 57.2957795

int main()
{
    double opposite,angle;
    float degrees,adjacent;

    puts("how tall is that tree?");
    printf("how far away is the tree in feet?");
    scanf("&f",&adjacent);
    __fpurge(stdin);
    printf("what angle is it to the tree top?");
    scanf("&f",&degrees);

  /*convert degrees to rads */

    angle = (double)degrees/RAD;

  /* get the tree height */

     opposite = tan(angle) * (double)adjacent;

     printf("that tree is %.2f feet tall.\n",opposite);
     return(0);
}

Name: Anonymous 2011-11-20 4:05

proper answer? Answer depends on what you input. and your problem is you used "&f" in scanf calls insead of "%f"

Name: Anonymous 2011-11-20 8:50

thanks anon for the save. its amazing how one's eyes skips over these things when you've already told yourself that you copied something correctly. also sorry for blaming the book for my mistake. i finally got the same answer as the book when i made the correction. I was just about to give up and leave this problem alone.

Name: Anonymous 2011-11-20 8:57

>>3
Programming isn't for you.

Name: Anonymous 2011-11-20 10:12

maybe but it was /prog/ that said it was as easy as getting a book and reading it til you understand it. i took up the challenge and dont regret it. like all things in life we are not born knowing how to do it til we understand the hows and whys or atleast thats what i believe. but since your a person who understands programming can you tell me the secret?

Name: Anonymous 2011-11-20 10:15

>>5
First, don't be a nigger.

Name: Anonymous 2011-11-20 10:20

>>3
When something doesn't work as expected, it's always your fault. Always.

Name: Anonymous 2011-11-20 17:29

>>7
Only in sepplesland.

Don't change these.
Name: Email:
Entire Thread Thread List