how to print any input year in digital block form

hello
I am new to programming and i found this problem that i need your help,
how to print a year like DIGITAL CLOCK NUMBER for any input four digit number
for example if input 1000 the output should be 1000 but each number should look like this in the block form for example number 0 is
#please dont mind those stars, i did not know to print it here, that is number zero
======
=****=
=****=
=****=
======


Last edited on
You'll need to parse the number into a string first (use std::to_string()). Then you access each element and print a certain amount of * and = per char. Once you reach the end of the string (std::string::size() - 1), you re-iterate until you complete the entire y-axis of char blocks.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <string>

int main()
{
    int num = 123;
    std::string numrep = std::to_string(num);
    for (int y = 0; y < 5; ++y)
    {
        for (int x = 0; x < numrep.size(); ++x)
        {
            switch (numrep[x])
            {
                case '0':
                    switch (y)
                    {
                        case 0: // First line
                            std::cout << "======";
                            break;
                        // More cases for the different y-value representations of the block.
                    }
                    break;
                // Other cases for all other nums
            }
        }
        std::cout << std::endl;
    }
    return 0;
}
Topic archived. No new replies allowed.