Thread: I declared it as int but it shows up as an char...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    17

    I declared it as int but it shows up as an char...

    First of all, hello I'm new here.

    Second, well I'm new to C programming, and I wrote this simple code.

    Code:
    #include <stdio.h>
    
    int main()
    
    {
       int a, b;
       printf("enter value one: ");
       scanf("%d", &a);
    
       printf("enter a second value: ");
       scanf("%d", &b);
    
       if (a < b)
          printf("%d is less than %b", a, b);
       else
          printf("%d is greater than %b", a, b);
       return 0;
    }
    I know it's kind of incomplete, but I just wanted to see if it worked or not.

    Ok, the compiler shows no errors or such, but when I run the executable, it goes like this:

    enter value one: 3
    enter a second value: 5
    3 is less than b
    As you can see, the second value I declared it as an integer and also used %d, not %c, so why is "3 is less than b" printed instead of 3 is less than 5?

    Thanks for your help and time.

    -:[XR3D403]:-
    Last edited by XR3D403; 02-10-2003 at 05:51 AM.

  2. #2
    Registered User The Junglist's Avatar
    Join Date
    Nov 2002
    Posts
    42
    >> printf("%d is less than %b", a, b);

    Try,

    printf("%d is less than %d", a, b);

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    hahaha sorry haha omfg that was so stupid

    thanks

    -:[XR3D403]:-

  4. #4
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    I hope you understand what means %d, %s and so one.
    It's for formatted outputs, %d means to print an Integer, %s means to print an String (array of chars).

    For a full list, you can try looking at google.

  5. #5
    Registered User
    Join Date
    Feb 2003
    Posts
    17
    Yes I know that, thanks Vber.

    {XR3D403}

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by XR3D403
    {XR3D403}
    If you always want that text at the bottom of your posts, you can put it in your signature. Go to User cp at the top of the screen then select Edit profile.
    It will then be automatically written in all your posts.

    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 8
    Last Post: 03-10-2008, 11:57 AM
  3. Game Won't Compile
    By jothesmo in forum C++ Programming
    Replies: 2
    Last Post: 04-01-2006, 04:24 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM