0

i have some problems with making this program. What i need to do is for a project in my class. what i need to do is similar to this: http://patorjk.com/software/taag/

I can print one letter a time but the problem is i cannot print somethong like "ABC" it prints them all in the same place. So if any of you can help me and show me the way i should do the printing would be so nice.

#include <iostream>
#include <string.h>
#include<windows.h>
#include <stdio.h>
using namespace std;

char A[4][12]={
"    //   ",
"  // //  ",
" /////// ",
"//     //"};

char B[5][12]={
" /////   ",
" //  //  ",
" /////   ",
" //  //  ",
" /////   "};

char C[5][12]={
"  /////  ",
" //      ",
" //      ",
" //      ",
"  /////  "};

char D[5][12]={
" /////   ",
" //  //  ",
" //   // ",
" //  //  ",
" /////   "};

char E[5][12]={
" /////   ",
" //      ",
" ////    ",
" //      ",
" /////   "};

char F[5][12]={
" /////   ",
" //      ",
" ////    ",
" //      ",
" //      "};

char G[5][12]={
"  /////  ",
" //      ",
"//  ///  ",
" //   // ",
"  /////  "};

char H[5][12]={
" //   // ",
" //   // ",
" /////// ",
" //   // ",
" //   // "};

char I[5][12]={
"    **   ",
"    //   ",
"    //   ",
"    //   ",
"    //   "};

char J[5][12]={
"      // ",
"      // ",
"      // ",
"  //  // ",
"   ////  "};

char K[5][12]={
" //  //  ",
" // //   ",
" ///     ",
" // //   ",
" //  //  "};



int main()
{
    int x, k = 0;
    char a[999];
    cin.get(a, 999);
    x = strlen(a);
    while (k < 6)
    {
        for (int i = 0; i <= x; i++)
        {
            if (a[i] == 'A')
                cout << A[k] << endl;
            if (a[i] == 'B')
                cout << B[k] << endl;
            if (a[i] == 'C')
                cout << C[k] << endl;
            if (a[i] == 'D')
                cout << D[k] << endl;
            if (a[i] == 'E')
                cout << E[k] << endl;
            if (a[i] == 'F')
                cout << F[k] << endl;
            if (a[i] == 'G')
                cout << G[k] << endl;
            if (a[i] == 'H')
                cout << H[k] << endl;
            if (a[i] == 'I')
                cout << I[k] << endl;
            if (a[i] == 'J')
                cout << J[k] << endl;
            if (a[i] == 'K')
                cout << K[k] << endl;
        }
        k = k + 1;
   }

    return 0;
}
user4581301
  • 33,082
  • 7
  • 33
  • 54
  • 2
    The big goal of Stack Overflow is to leave a repository of questions and answers to programming problems for future programmers. In order to do this question need to be able to last as long as the site does. This means links to offsite resources are of limited use. As soon as pastebin garbage collects, shuffles it's links, or becomes an adult entertainment site, your code is lost and the question becomes useless. I've pasted your code in, but will also vote to close for lack of a [mcve]. This is a bug you should be able isolate and figure out with a lot less code. – user4581301 Mar 13 '18 at 22:32
  • 1
    You're adding a line break after every output statement instead of at the end of the `while (k < 6)` loop. What did you expect? You're loop also runs one extra time and causes undefined behavior due to out-of-bounds array access. You should use `std::string`s instead of C-style strings, and you could probably use a [good book](https://stackoverflow.com/q/388242/9254539). Also, a switch case would be better instead of a bunch of if statements (at least use `else if`). – eesiraed Mar 14 '18 at 04:15

1 Answers1

0

I've written a very similar program to print integers in large size by printing hashes. Here is the program:

/**
Author:- Mayukh Datta
**/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define H 7
#define W 8 //one extra room in the char array is required for storing '\0'
void main()
{
    char num[11];  //here too one extra room is needed for the '\0'
    char c;  //for option
    int i, j, k;
    //declaring char 2D arrays and initializing with hash-printed digits
    char zero[H][W]={" ##### ", //H=0
                     " #   # ", //H=1
                     " #   # ", //H=2
                     " #   # ", //H=3
                     " #   # ", //H=4
                     " #   # ", //H=5
                     " ##### "},//H=6

         one[H][W]={"   #   ",
                    "  ##   ",
                    "   #   ",
                    "   #   ",
                    "   #   ",
                    "   #   ",
                    " ##### "},

         two[H][W]={" ##### ",
                    "     # ",
                    "     # ",
                    " ##### ",
                    " #     ",
                    " #     ",
                    " ##### "},

         three[H][W]={" ##### ",
                      "     # ",
                      "     # ",
                      " ##### ",
                      "     # ",
                      "     # ",
                      " ##### "},

         four[H][W]={" #     ",
                     " #   # ",
                     " #   # ",
                     " ##### ",
                     "     # ",
                     "     # ",
                     "     # "},

         five[H][W]={" ##### ",
                     " #     ",
                     " #     ",
                     " ##### ",
                     "     # ",
                     "     # ",
                     " ##### "},

         six[H][W]={" ##### ",
                    " #     ",
                    " #     ",
                    " ##### ",
                    " #   # ",
                    " #   # ",
                    " ##### "},

         seven[H][W]={" ##### ",
                      "     # ",
                      "     # ",
                      "  #### ",
                      "     # ",
                      "     # ",
                      "     # "},

         eight[H][W]={" ##### ",
                      " #   # ",
                      " #   # ",
                      " ##### ",
                      " #   # ",
                      " #   # ",
                      " ##### "},

         nine[H][W]={" ##### ",
                     " #   # ",
                     " #   # ",
                     " ##### ",
                     "     # ",
                     "     # ",
                     "     # "};

    do
    {
        printf("Enter a number upto 10 digits:- ");
        fflush(stdin);
        gets(num);
        if(strlen(num)>10)
           printf("\nYou must enter a number upto 10 digits.\nTry again!\n");
        else
        {
            printf("\n");

            k=1;
            j=0;  //controls H of each digit
            while(k<=7)  //controls height
            {
                for(i=0;i<strlen(num);i++)  //reads each digit
                {
                    if(num[i]=='0')
                        printf("%s", zero[j]);
                    else if(num[i]=='1')
                        printf("%s", one[j]);
                    else if(num[i]=='2')
                        printf("%s", two[j]);
                    else if(num[i]=='3')
                        printf("%s", three[j]);
                    else if(num[i]=='4')
                        printf("%s", four[j]);
                    else if(num[i]=='5')
                        printf("%s", five[j]);
                    else if(num[i]=='6')
                        printf("%s", six[j]);
                    else if(num[i]=='7')
                        printf("%s", seven[j]);
                    else if(num[i]=='8')
                        printf("%s", eight[j]);
                    else if(num[i]=='9')
                        printf("%s", nine[j]);
                }
                printf("\n");
                k++;
                j++;
            }
        }
        printf("\nEnter Y to continue:- ");
        fflush(stdin);
        scanf("%c", &c);
    }while(c=='Y'||c=='y');
}

Understand how the loop works in my program. Link: http://www.thecoducer.com/2017/08/printing-the-number-in-large-size.html

Mayukh Datta
  • 91
  • 1
  • 4