C program help

Discussion in 'Programming General' started by fball56, Jan 21, 2012.

C program help
  1. Unread #1 - Jan 21, 2012 at 3:38 PM
  2. fball56
    Joined:
    Nov 8, 2011
    Posts:
    179
    Referrals:
    0
    Sythe Gold:
    0

    fball56 Active Member

    C program help

    I am taking a programming class this semester and I am have trouble wit this homework. I think its called C so I hope this is the right place to post.

    Here is the problem:
    Problem: Given as integers (three in all) an angle in degrees, minutes, and seconds display the value converted
    into radians.

    Example Execution #1:
    Enter number of degrees: 180
    Enter number of minutes: 0
    Enter number of seconds: 0
    Data Entered: 180° 0' 0"
    Radians Conversion: 3.1416

    I have this program, but I can't compile it. What did I do wrong?

    Code:
    #include<stdio.h>
    
    int main(void)
    {
      // Local Declarations
      float d; // This will be the degrees of the angle
      float m; // This will be the minutes of the angle
      float s; // This will be the seconds of the angle
      float angle; // This will be the final angle in radians
    
      // Statements
      printf("\nEnter the number of degrees:");
      scanf("%f", &d);
      printf("\nEnter the number of minutes:");
      scanf("%f", &m);
      printf("\nEnter the number of seconds:");
      scanf("%f", &s);
    
     // Converting to radians
     angle =( 3.14159 / 180 ) * (d + (((m * 60) + 30) / 3600) )
    
     // The angle in radians
     printf("\nAngle in Radians: %5.5f\n\n", angle);
    
     return (0);
    }
     
  3. Unread #2 - Jan 21, 2012 at 6:34 PM
  4. Nullware
    Joined:
    Jan 30, 2007
    Posts:
    1,761
    Referrals:
    4
    Sythe Gold:
    0

    Nullware Guru

    C program help

    Hi, you have just 2 small errors. Usually a good compiler will tell you them. Here they are with explanations.

    You can't have the type of a variable without its name in the function declaration so just remove the "void" and have no parameters.
    Code:
    int main()
    Something wrong before "printf" on line 23 would mean looking at previous lines since that's the start of the line and sure enough the line before is missing the end semi-colon.
     
  5. Unread #3 - Jan 21, 2012 at 6:59 PM
  6. fball56
    Joined:
    Nov 8, 2011
    Posts:
    179
    Referrals:
    0
    Sythe Gold:
    0

    fball56 Active Member

    C program help

    Thanks you so much!! That was it. It told me there were errors, but I didn't know what they meant.
     
< vb.net label problem | [Source] Easy global hotkeys for VB.net >

Users viewing this thread
1 guest


 
 
Adblock breaks this site