Thread: Help with programming code!!!

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

    Help with programming code!!!

    Hello Everyone .

    I've been working on a code which scans up to 4 input numbers and prints them Horizontally on a "3*5" grid. My code works fine except that it prints vertically instead. I understand I'm supposed to use a 2- dimensional array to fix this problem but I don't know how to go about it.Can anyone please help ?

    Thank you very much.

    Here is my code so far:

    Code:
    
    
    Code:
    #include<stdio.h>
    
    
    int main( void )
    {
       /* declearing the variables 'a' and 'digit' */
       
       int digit;
       int a;
       
       /* Setting up the array which will scan the variable 'digit' four times*/
       for(a=0;a<=3;a++)
       
    {
    
    
       scanf("%d",&digit);
    
    
       if(digit == 1)
       {
          printf("\n\n  *\n  *\n  *\n  *\n  *");
       }
    
    
       else if(digit == 2)
       {
          printf("\n\n* * *\n    *\n* * *\n* \n* * *");
       }
    
    
       else if(digit == 3)
       {
          printf("\n\n* * *\n    *\n* * *\n    *\n* * *");
       }
    
    
       else if(digit == 4)
       {
          printf("\n\n*   *\n*   *\n* * *\n    *\n    *");
       }
    
    
       else if(digit == 5 ) 
       { 
          printf("\n\n* * *\n*   \n* * *\n    *\n* * *\n");
       }
    
    
       else if(digit == 6)
       {
          printf("\n\n* * *\n* \n* * *\n*   *\n* * *");
       }
    
    
       else if(digit == 7)
       {
          printf("\n\n* * *\n    *\n    *\n    *\n    *\n");
       }
       
       else if(digit == 8)
       {
          printf("\n\n* * *\n*   *\n* * *\n*   *\n* * *\n");
       }
    
    
       else if(digit == 9)
       {
          printf("\n\n* * *\n*   *\n* * *\n*   *\n* * *\n");
       }
    
    
       else if(digit == 0)
       {
          printf("\n\n* * *\n*   *\n*   *\n*   *\n* * *\n");
       } 
       else if (digit > 9)
       {
          printf("\n Invalid Number(s)!Please input four digits between 0 and 9 \n"); 
       }
    
    
    } 
    
    
    
    
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Stop putting newlines all over the place. Only put a newline when you want a new line.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Step 1: Get all 4 input digits before outputting the large digits using stars "*"
    Step 2: Do the large digit output
    Out top row of all four digits
    The do the next row.
    repeat till all rows are done.

    Tim S.

  4. #4
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    your "9" was messed up.

    Code:
    /* prog1.c */
    
    #include<stdio.h>
    
    
    int main( void )
    {
       /* declearing the variables 'a' and 'digit' */
       
       int digit;
       int a;
       
       /* Setting up the array which will scan the variable 'digit' four times*/
       for(a=0;a<=3;a++)
       
    {
    
    
       scanf("%d",&digit);
    
    /*   printf("*\n\n\n\n"); */
    
    
    
       if(digit == 1)
       {
          printf("\n\n  *\n  *\n  *\n  *\n  *");
       }
    
    
       else if(digit == 2)
       {
          printf("\n\n* * *\n    *\n* * *\n* \n* * *");
       }
    
    
       else if(digit == 3)
       {
          printf("\n\n* * *\n    *\n* * *\n    *\n* * *");
       }
    
    
       else if(digit == 4)
       {
          printf("\n\n*   *\n*   *\n* * *\n    *\n    *");
       }
    
    
       else if(digit == 5 ) 
       { 
          printf("\n\n* * *\n*   \n* * *\n    *\n* * *\n");
       }
    
    
       else if(digit == 6)
       {
          printf("\n\n* * *\n* \n* * *\n*   *\n* * *");
       }
    
    
       else if(digit == 7)
       {
          printf("\n\n* * *\n    *\n    *\n    *\n    *\n");
       }
       
       else if(digit == 8)
       {
          printf("\n\n* * *\n*   *\n* * *\n*   *\n* * *\n");
       }
    
    
       else if(digit == 9)
       {
          printf("\n\n* * *\n*   *\n* * *\n    *\n    *\n");
       }
    
    
       else if(digit == 0)
       {
          printf("\n\n* * *\n*   *\n*   *\n*   *\n* * *\n");
       } 
       else if (digit > 9)
       {
          printf("\n Invalid Number(s)!Please input four digits between 0 and 9 \n"); 
       }
    
    
    } 
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 11-19-2011, 10:55 AM
  2. Replies: 8
    Last Post: 11-19-2011, 01:29 AM
  3. Can someone help me with my C programming lottery code?
    By OvdoMan9 in forum C Programming
    Replies: 2
    Last Post: 09-02-2010, 11:07 PM
  4. Does C++ be the code behind of DotNet programming for Web
    By rchiu5hk in forum C++ Programming
    Replies: 4
    Last Post: 09-03-2009, 06:10 AM