Thread: Help Please.

  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    29

    Help Please.

    I am an absolute beginner to C programming.

    I need help with this program. Please help. Thanks in advance.

    Here is the problem.

    Enter a float number. Print the last digit of the integer part of the number.

    Below is the code I wrote. But I am getting an error saying "syntax error before int"


    Code:
    #include <stdio.h>
    #include <conio.h>
    
    
    void main()
    {
         float a; 
         int b,last;
         
         printf ("value: ");
         scanf ("%f", &a);
         
         b = int(a);
         last = b%10;
         
         printf ("%d", last);
         getch();
         
    }

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,267
    Your casting syntax is wrong.
    Code:
    b = int(a);
    should be
    Code:
    b = (int)a;

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,794
    also it should be
    int main(void) - read FAQ

    conio.h and getch are not standard -
    remove line:
    #include <conio.h>
    and replace getch with getchar
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  4. #4
    Registered User
    Join Date
    Feb 2008
    Posts
    29
    Thanks Guys.
    Works Now :-)

Popular pages Recent additions subscribe to a feed