Basic C programming help

This is a discussion on Basic C programming help within the C Programming forums, part of the General Programming Boards category; I cannot seem to figure out why this will not work!? http://i.imgur.com/PuYO8.png That is the code as you can see ...

  1. #1
    Registered User
    Join Date
    Jan 2012
    Posts
    2

    Basic C programming help

    I cannot seem to figure out why this will not work!?

    http://i.imgur.com/PuYO8.png

    That is the code as you can see everything is ok and all should be working fine.

    http://i.imgur.com/gnr4v.png

    Now you can see i enter 111 into the stdin, this should be represented in the next picture as 111.

    http://i.imgur.com/Xj62h.png

    But as you can see that's not the case, for whatever reason num4 ALWAYS prints itself even when the if conditions are against it. When i delete num4 completely from the code everything works as per usual. Am i doing something wrong?? cos the code all looks identical and should be working fine surely?? Sorry i don't know much about C programming :/

  2. #2
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Am i doing something wrong??
    Yes. You're posting pictures of your code instead of your code.

  3. #3
    Registered User
    Join Date
    Jan 2012
    Posts
    2
    Code:
    #include <stdio.h>
     
    int main( void )
    {
       int num1;
       int num2;
       int num3;
       int num4;
       
       scanf ("%1d", &num1);
       scanf ("%1d", &num2);
       scanf ("%1d", &num3);
       scanf ("%1d", &num4);
        if (num1 == 1)
    {
       printf ("0\n0\n0\n0\n0", num1); 
    }
       if (num2 == 1)
     {
      printf (" \n\n0\n0\n0\n0\n0", num2); 
     }
       if (num3 == 1)
    {
       printf (" \n\n0\n0\n0\n0\n0", num3); 
    }
       if (num4 == 1)
       {
       printf (" \n\n0\n0\n0\n0\n0", num4); 
       }

  4. #4
    Registered User camel-man's Avatar
    Join Date
    Jan 2011
    Location
    Under the moon
    Posts
    643
    you need to use the %d in your printf to display the numbers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic c programming help
    By benrogers in forum C Programming
    Replies: 12
    Last Post: 01-24-2011, 05:01 PM
  2. basic C programming help
    By helfone in forum C Programming
    Replies: 3
    Last Post: 10-22-2007, 10:54 AM
  3. Very basic programming help please
    By xrated in forum C++ Programming
    Replies: 8
    Last Post: 08-14-2006, 04:02 PM
  4. basic C-programming Q
    By slyonedoofy in forum C Programming
    Replies: 2
    Last Post: 10-30-2002, 09:54 PM
  5. Basic Programming
    By plexy1 in forum C Programming
    Replies: 2
    Last Post: 09-05-2001, 03:03 PM

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