Help Please.

This is a discussion on Help Please. within the C Programming forums, part of the General Programming Boards category; I am an absolute beginner to C programming. I need help with this program. Please help. Thanks in advance. Here ...

  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,246
    Your casting syntax is wrong.
    Code:
    b = int(a);
    should be
    Code:
    b = (int)a;

  3. #3
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21