Thread: Scanf

  1. #1
    Registered User
    Join Date
    Nov 2001

    Unhappy Scanf

    No matter what figure I input. It come out the same figure. Please help me. I think there are some thing wrong of " scanf(%ld0". Please help me. thanks a lot.

    #include <stdio.h>

    long tax_in,tax_pay; //tax_in=taxable income,tax_pay=tax payable


    printf("Please input your amount of taxable income or input -9999 to exit the program.\n");

    scanf ("%ld" , &tax_in);

    while (tax_in !=-9999)
    if ((tax_in>0) && (tax_in<999999))
    if ((tax_in>0) && (tax_in<=20000))



    if ((tax_in>20000) && (tax_in<=50000))



    if ((tax_in>50000) && (tax_in<=100000))



    if ((tax_in>100000) && (tax_in<=999999))


    printf( "Your tax payable is %ld\n", &tax_in);



    printf ( "Invalid amount, please try again.\n");
    printf ( "Enter taxable income: ");

    scanf ("%ld" , &tax_in);



  2. #2
    S Lee,

    Look at you last line in your while:

    printf( "Your tax payable is %ld\n", &tax_in);
    The variable you are printing is the same variable the user entered. It should be:

    printf("Your tax payable is %ld\n", tax_pay);
    Also, why declare them as longs? If I remember correctly a long and an int both are 4 bytes.

    Another thing, it seems like you have a few braces missing inside your while (on the nested if-else's), may wanna double check that.

    {forgot that printf's don't take addresses}
    Last edited by DrakkenKorin; 11-29-2001 at 09:50 AM.

    Get off my Intarweb!!!!

  3. #3
    Registered User
    Join Date
    Sep 2001
    printf( "Your tax payable is %ld\n", &tax_in);

    You aren't supposed to pass addresses to printf. Just pass the variable itself...

    printf( "Your tax payable is %ld\n", tax_in);
    Callou collei we'll code the way
    Of prime numbers and pings!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. scanf() consideres useless
    By Snafuist in forum C Programming
    Replies: 15
    Last Post: 02-18-2009, 08:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 04:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 01:48 PM
  4. Scanf and integer...
    By penny in forum C Programming
    Replies: 3
    Last Post: 04-24-2003, 06:36 AM
  5. scanf - data is "put back" - screws up next scanf
    By voltson in forum C Programming
    Replies: 10
    Last Post: 10-14-2002, 04:34 AM