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
======
=****=
=****=
=****=
======
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.
#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;
}