Skip to main content
added 2144 characters in body
Source Link

Problem solved: in the draw_horizontal_row() the index of the main loop is override by the else second loop.

Use the variable 'j' as follow:

else {
    for (int j = 0; j < size + 2; j++) {
        std::cout << " ";
    }
    if (i < number_of_digits - 1) {
        std::cout << " "; //A space follows each digit drawn except the last one. 
    }
}

Instead of:

else {
    for (int i = 0; i < size + 2; i++) { // the local 'i' override loop 'i'
        std::cout << " ";
    }
    if (i < number_of_digits - 1) {
        std::cout << " "; //A space follows each digit drawn except the last one. 
    }
}

Be also careful in draw_vertical_row() where 'i' is reuse in the 3 levels of loop. Use 3 different variable names ( i, j & k):

void draw_vertical_row(int* digits_to_draw, int rowNo, int size, int number_of_digits) {
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < number_of_digits; j++) {
            if (lcd_digits_images[digits_to_draw[j]][rowNo].compare("  |") == 0) {
                for (int k = 0; k < size+1; k++) {
                    std::cout << " ";
                }
                std::cout << "|";

            }
            else if (lcd_digits_images[digits_to_draw[j]][rowNo].compare("|  ") == 0) {
                std::cout << "|";
                for (int k = 0; k < size + 1; k++) {
                    std::cout << " ";
                }
            }
            else {
                std::cout << "|";
                for (int k = 0; k < size; k++) {
                    std::cout << " ";
                }
                std::cout << "|";
            }

            if (j < number_of_digits - 1) {
                std::cout << " ";//A space follows each digit drawn except the last one. 
            }

        }

        std::cout << std::endl; //After drawing the digits, we add a blank line to seperate our output. 
    }
}

Problem solved: in the draw_horizontal_row() the index of the main loop is override by the else second loop.

Use the variable 'j' as follow:

else {
    for (int j = 0; j < size + 2; j++) {
        std::cout << " ";
    }
    if (i < number_of_digits - 1) {
        std::cout << " "; //A space follows each digit drawn except the last one. 
    }
}

Instead of:

else {
    for (int i = 0; i < size + 2; i++) { // the local 'i' override loop 'i'
        std::cout << " ";
    }
    if (i < number_of_digits - 1) {
        std::cout << " "; //A space follows each digit drawn except the last one. 
    }
}

Be also careful in draw_vertical_row() where 'i' is reuse in the 3 levels of loop. Use 3 different variable names ( i, j & k):

void draw_vertical_row(int* digits_to_draw, int rowNo, int size, int number_of_digits) {
    for (int i = 0; i < size; i++) {
        for (int j = 0; j < number_of_digits; j++) {
            if (lcd_digits_images[digits_to_draw[j]][rowNo].compare("  |") == 0) {
                for (int k = 0; k < size+1; k++) {
                    std::cout << " ";
                }
                std::cout << "|";

            }
            else if (lcd_digits_images[digits_to_draw[j]][rowNo].compare("|  ") == 0) {
                std::cout << "|";
                for (int k = 0; k < size + 1; k++) {
                    std::cout << " ";
                }
            }
            else {
                std::cout << "|";
                for (int k = 0; k < size; k++) {
                    std::cout << " ";
                }
                std::cout << "|";
            }

            if (j < number_of_digits - 1) {
                std::cout << " ";//A space follows each digit drawn except the last one. 
            }

        }

        std::cout << std::endl; //After drawing the digits, we add a blank line to seperate our output. 
    }
}
Source Link

There is a problem with the space between characters and especially when entering "2 18" (see below):

2 18
     --
   | |  |
   | |  |
     --
   | |  |
   | |  |
     --

instead of:

2 18
      --
   | |  |
   | |  |
      --
   | |  |
   | |  |
      --