Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7056143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:49:57+00:00 2026-05-28T03:49:57+00:00

The code below should take the input, store it then display LEDs that give

  • 0

The code below should take the input, store it then display LEDs that give the number as a display. However it gives random LEDs, not the correct one. I’ve checked a few things but I can’t see what’s wrong, can you help?

#include <stdio.h>

int main( void )
{
   /* Declare a data variable for each pixel. */
   int a1, a2, a3, a4, a5 =0;
   int b1, b2, b3, b4, b5 =0;
   int c1, c2, c3, c4, c5 =0;
   int d1, d2, d3, d4, d5 =0;
   int e1, e2, e3, e4, e5 =0;
   int f1, f2, f3, f4, f5 =0;
   int g1, g2, g3, g4, g5 =0;
   int h1, h2, h3, h4, h5 =0;
   int i1, i2, i3, i4, i5 =0;
   int j1, j2, j3, j4, j5 =0;
   int k1, k2, k3, k4, k5 =0;
   int l1, l2, l3, l4, l5 =0;


   /* Collect the data from stdin and store in a string */

      char str[6];
      scanf("%s", str);
      int a = str[0] - '0';
      int b = str[1] - '0';
      int c = str[2] - '0';
      int d = str[3] - '0';

   /* Change the pixels to store the shape of the numbers to be displayed */   

      switch ( a ) {
      case 0:
        a1, b1, c1, a2, c2, a3, c3, a4, c4, a5, b5, c5 = 1;
        break;
      case 1:
        c1, c2, c3, c4, c5 = 1;
        break;
      case 2:
        a1, b1, c1, c2, a3, b3, c3, a4, a5, b5, c5 = 1;
        break;
      case 3:
        a1, b1, c1, c2, a3, b3, c3, c4, a5, b5, c5 = 1;
        break;
      case 4:
        a1, c1, a2, c2, a3, b3, c3, b4, b5 = 1;
        break;
      case 5:
        a1, b1, c1, a2, a3, b3, c3, c4, a5, b5, c5 = 1;
        break;
      case 6:
        a1, b1, c1, a2, a3, b3, c3, a4, c4, a5, b5, c5 = 1;
        break;
      case 7:
        a1, b1, c1, c2, c3, c4, c5 = 1;
        break;
      case 8:
        a1, b1, c1, a2, c2, a3, b3, c3, a4, c4, a5, b5, c5 = 1;
        break;
      case 9:
        a1, b1, c1, a2, c2, a3, b3, c3, c4, c5 = 1;
        break; 
      default:
        printf("Please input a valid number");
        return 0;
          break;
}

switch ( b ) {
      case 0:
        d1, e1, f1, d2, f2, d3, f3, d4, f4, d5, e5, f5 = 1;
        break;
      case 1:
        f1, f2, f3, f4, f5 = 1;
        break;
      case 2:
        d1, e1, f1, f2, d3, e3, f3, d4, d5, e5, f5 = 1;
        break;
      case 3:
        d1, e1, f1, f2, d3, e3, f3, f4, d5, e5, f5 = 1;
        break;
      case 4:
        d1, f1, d2, f2, d3, e3, f3, e4, e5 = 1;
        break;
      case 5:
        d1, e1, f1, d2, d3, e3, f3, f4, d5, e5, f5 = 1;
        break;
      case 6:
        d1, e1, f1, d2, d3, e3, f3, d4, f4, d5, e5, f5 = 1;
        break;
      case 7:
        d1, e1, f1, f2, f3, f4, f5 = 1;
        break;
      case 8:
        d1, e1, f1, d2, f2, d3, e3, f3, d4, f4, d5, e5, f5 = 1;
        break;
      case 9:
        d1, e1, f1, d2, f2, d3, e3, f3, f4, f5 = 1;
        break; 
      default:
        printf("Please input a valid number");
        return 0;
          break;
}

switch ( c ) {
      case 0:
        g1, h1, i1, g2, i2, g3, i3, g4, i4, g5, h5, i5 = 1;
        break;
      case 1:
        i1, i2, i3, i4, i5 = 1;
        break;
      case 2:
        g1, h1, i1, i2, g3, h3, i3, g4, g5, h5, i5 = 1;
        break;
      case 3:
        g1, h1, i1, i2, g3, h3, i3, i4, g5, h5, i5 = 1;
        break;
      case 4:
        g1, i1, g2, i2, g3, h3, i3, h4, h5 = 1;
        break;
      case 5:
        g1, h1, i1, g2, g3, h3, i3, i4, g5, h5, i5 = 1;
        break;
      case 6:
        g1, h1, i1, g2, g3, h3, i3, g4, i4, g5, h5, i5 = 1;
        break;
      case 7:
        g1, h1, i1, i2, i3, i4, i5 = 1;
        break;
      case 8:
        g1, h1, i1, g2, i2, g3, h3, i3, g4, i4, g5, h5, i5 = 1;
        break;
      case 9:
        g1, h1, i1, g2, i2, g3, h3, i3, i4, i5 = 1;
        break; 
      default:
        printf("Please input a valid number");
        return 0;
          break;
}

switch ( d ) {
      case 0:
        j1, k1, l1, j2, l2, j3, l3, j4, l4, j5, k5, l5 = 1;
        break;
      case 1:
        l1, l2, l3, l4, l5 = 1;
        break;
      case 2:
        j1, k1, l1, l2, j3, k3, l3, j4, j5, k5, l5 = 1;
        break;
      case 3:
        j1, k1, l1, l2, j3, k3, l3, l4, j5, k5, l5 = 1;
        break;
      case 4:
        j1, l1, j2, l2, j3, k3, l3, k4, k5 = 1;
        break;
      case 5:
        j1, k1, l1, j2, j3, k3, l3, l4, j5, k5, l5 = 1;
        break;
      case 6:
        j1, k1, l1, j2, j3, k3, l3, j4, l4, j5, k5, l5 = 1;
        break;
      case 7:
        j1, k1, l1, l2, l3, l4, l5 = 1;
        break;
      case 8:
        j1, k1, l1, j2, l2, j3, k3, l3, j4, l4, j5, k5, l5 = 1;
        break;
      case 9:
        j1, k1, l1, j2, l2, j3, k3, l3, l4, l5 = 1;
        break; 
      default:
        printf("Please input a valid number");
        return 0;
          break;
}

      /* Display the pixels in the correct order */

         if (a1 == 1 )
            printf("O");
         else
            printf(" ");

         if (b1 == 1 )
            printf("O");
         else
            printf(" ");

         if (c1 == 1 )
            printf("O");
         else
            printf(" ");

         if (d1 == 1 )
            printf("O");
         else
            printf(" ");

         if (e1 == 1 )
            printf("O");
         else
            printf(" ");

         if (f1 == 1 )
            printf("O");
         else
            printf(" ");

         if (g1 == 1 )
            printf("O");
         else
            printf(" ");

         if (h1 == 1 )
            printf("O");
         else
            printf(" ");

         if (i1 == 1 )
            printf("O");
         else
            printf(" ");

         if (j1 == 1 )
            printf("O");
         else
            printf(" ");

         if (k1 == 1 )
            printf("O");
         else
            printf(" ");

         if (l1 == 1 )
            printf("O\n");
         else
            printf(" \n");

         if (a2 == 1 )
            printf("O");
         else
            printf(" ");

         if (b2 == 1 )
            printf("O");
         else
            printf(" ");

         if (c2 == 1 )
            printf("O");
         else
            printf(" ");

         if (d2 == 1 )
            printf("O");
         else
            printf(" ");

         if (e2 == 1 )
            printf("O");
         else
            printf(" ");

         if (f2 == 1 )
            printf("O");
         else
            printf(" ");

         if (g2 == 1 )
            printf("O");
         else
            printf(" ");

         if (h2 == 1 )
            printf("O");
         else
            printf(" ");

         if (i2 == 1 )
            printf("O");
         else
            printf(" ");

         if (j2 == 1 )
            printf("O");
         else
            printf(" ");

         if (k2 == 1 )
            printf("O");
         else
            printf(" ");

         if (l2 == 1 )
            printf("O\n");
         else
            printf(" \n");

         if (a3 == 1 )
            printf("O");
         else
            printf(" ");

         if (b3 == 1 )
            printf("O");
         else
            printf(" ");

         if (c3 == 1 )
            printf("O");
         else
            printf(" ");

         if (d3 == 1 )
            printf("O");
         else
            printf(" ");

         if (e3 == 1 )
            printf("O");
         else
            printf(" ");

         if (f3 == 1 )
            printf("O");
         else
            printf(" ");

         if (g3 == 1 )
            printf("O");
         else
            printf(" ");

         if (h3 == 1 )
            printf("O");
         else
            printf(" ");

         if (i3 == 1 )
            printf("O");
         else
            printf(" ");

         if (j3 == 1 )
            printf("O");
         else
            printf(" ");

         if (k3 == 1 )
            printf("O");
         else
            printf(" ");

         if (l3 == 1 )
            printf("O\n");
         else
            printf(" \n");

         if (a4 == 1 )
            printf("O");
         else
            printf(" ");

         if (b4 == 1 )
            printf("O");
         else
            printf(" ");

         if (c4 == 1 )
            printf("O");
         else
            printf(" ");

         if (d4 == 1 )
            printf("O");
         else
            printf(" ");

         if (e4 == 1 )
            printf("O");
         else
            printf(" ");

         if (f4 == 1 )
            printf("O");
         else
            printf(" ");

         if (g4 == 1 )
            printf("O");
         else
            printf(" ");

         if (h4 == 1 )
            printf("O");
         else
            printf(" ");

         if (i4 == 1 )
            printf("O");
         else
            printf(" ");

         if (j4 == 1 )
            printf("O");
         else
            printf(" ");

         if (k4 == 1 )
            printf("O");
         else
            printf(" ");

         if (l4 == 1 )
            printf("O\n");
         else
            printf(" \n");

         if (a5 == 1 )
            printf("O");
         else
            printf(" ");

         if (b5 == 1 )
            printf("O");
         else
            printf(" ");

         if (c5 == 1 )
            printf("O");
         else
            printf(" ");

         if (d5 == 1 )
            printf("O");
         else
            printf(" ");

         if (e5 == 1 )
            printf("O");
         else
            printf(" ");

         if (f5 == 1 )
            printf("O");
         else
            printf(" ");

         if (g5 == 1 )
            printf("O");
         else
            printf(" ");

         if (h5 == 1 )
            printf("O");
         else
            printf(" ");

         if (i5 == 1 )
            printf("O");
         else
            printf(" ");

         if (j5 == 1 )
            printf("O");
         else
            printf(" ");

         if (k5 == 1 )
            printf("O");
         else
            printf(" ");

         if (l5 == 1 )
            printf("O");
         else
            printf(" ");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:49:58+00:00Added an answer on May 28, 2026 at 3:49 am

    A couple of things:

    int a1, a2, a3, a4, a5 =0;
    

    That’s only actually initialising a5, not any other of the variables, so a1 to a4 are uninitialised so will contain random values.

    case 0:
            a1, b1, c1, a2, c2, a3, c3, a4, c4, a5, b5, c5 = 1;
    

    You’re not assigning any variables except c5 to 1. You could do this instead though, which isn’t much more code:

            a1 = b1 = c1 = a2 = c2 = a3 = c3 = a4 = c4 = a5 = b5 = c5 = 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In the function below, the code should take a parameter, 1) display an alert
The below code seems like it should work; however, the blob in the database
The code below takes an array value, if it's key exist it should echo
When retrieving objects from an NSMutableArray in cocoa-touch is the below code ok? Should
The code below shows a sample that I've used recently to explain the different
The code below gives me this mysterious error, and i cannot fathom it. I
The code below gives an error: Property 'Int32 Key' is not defined for type
Classic scenario: Take user input, get a search-result and display it in pages to
Take a look on the code below: $t=77; date(H:i:s, $t); It returns 21:01:17 The
I have the jquery code below that returns a list of ID's like this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.