Scanf

This is a discussion on Scanf within the C Programming forums, part of the General Programming Boards category; No matter what figure I input. It come out the same figure. Please help me. I think there are some ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    1

    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

    main()

    {
    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))

    tax_pay=tax_in*0.02;

    else

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

    tax_pay=(tax_in-20000)*0.07+400;

    else

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

    tax_pay=(tax_in-50000)*0.15+2500;

    else

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

    tax_pay=(tax_in-100000)*0.20+10000;


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




    }

    else

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

    scanf ("%ld" , &tax_in);

    }


    }

  2. #2
    Nosepicker DrakkenKorin's Avatar
    Join Date
    Nov 2001
    Posts
    407
    S Lee,

    Look at you last line in your while:

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

    Code:
    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 08:50 AM.
    DrakkenKorin

    Get off my Intarweb!!!!

  3. #3
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    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, 07:35 AM
  2. Help with a basic scanf procedure.
    By killpoppop in forum C Programming
    Replies: 9
    Last Post: 11-03-2008, 03:39 PM
  3. Replies: 2
    Last Post: 02-20-2005, 12: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

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