C++ help

jai6638

Golden Member
Apr 9, 2004
1,790
0
0
Hey there..

Trying to do this simple C++ program where I have to print my name but honestly, its not working right.. I figured that I would have to simply put my letters in the quotes but the problem is that the lines of the letters keep getting messed up and I have to make adjustments.. Why is this so?

Moreover, after the S, there is no space on the right so the W messes the whole output out.. Why?

#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;

int main()
{

int i,j;
char A[6][11]={
{" J"},
{" J"},
{" J"},
{" J"},
{"J J"},
{" JJ"}};

char B[6][11]={
{" "},
{" AA "},
{" A A "},
{" A A "},
{" A AA A "},
{"A A" }};

char C[6][11]={
{" "},
{" IIIII"},
{" I "},
{" I "},
{" I "},
{"IIIII"}};


char D[6][11]={
{" FFFFFF "},
{" F "},
{" FFFF "},
{" F "},
{" F "},
{"F"}};

char E[6][11]={
{" "},
{" AA"},
{" A A"},
{" A A"},
{" A AA A"},
{"A A" }};

char F[6][11]={
{" RRR"},
{" R R"},
{" RRR"},
{" RR"},
{" R R"},
{" R R" }};

char G[6][11]={
{" "},
{" SSSSSS"},
{" SS " },
{" SSSSS"},
{" SS"},
{" SSSSSS"}};

char H[6][11]={
{" W W "},
{" W W "},
{" W W "},
{" W W "},
{" W WW W "},
{" WW WW"}};


for(i=0;i<6;i++)
{
for(j=0;j<11;j++)
{
cout<<A[j];
}

for(j=0;j<11;j++)
{
cout<<B[j];
}

for(j=0;j<11;j++)
{
cout<<C[j];
}


for(j=0;j<11;j++)
{
cout<<D[j];
}

for(j=0;j<11;j++)
{
cout<<E[j];
}

for(j=0;j<11;j++)
{
cout<<F[j];
}

for(j=0;j<11;j++)
{
cout<<G[j];
}

for(j=0;j<11;j++)
{
cout<<H[j];
}

cout<<endl;

}


return 0;
}



Thanks much..
 

drebo

Diamond Member
Feb 24, 2006
7,034
1
81
A typical console screen (DOS included) only has 80 columns. You're trying to use 88.

Hack off the W and see if the rest displays properly. If it does, rework it to only need 80 columns.
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
I'm not entirely sure what your problem is. More clarification would be nice.

One problem that I notice is that your strings even including the null terminators are less than 11 characters in length, so if you print the whole buffer, you'll probably get a bunch of weird characters. Try just outputting the string directly (e.g. cout << H[ i ]), or loop until you see a '\0' character.
 

jai6638

Golden Member
Apr 9, 2004
1,790
0
0
Originally posted by: dighn
I'm not entirely sure what your problem is. More clarification would be nice.

One problem that I notice is that your strings even including the null terminators are less than 11 characters in length, so if you print the whole buffer, you'll probably get a bunch of weird characters. Try just outputting the string directly (e.g. cout << H[ i ]), or loop until you see a '\0' character.

THe problem is that when it prints the A, the spacing is all messed up... For example, in the code, I enter a proper A and expect for it to be printed out.

I figure that it should print the A letters with the same spacing to give me the above letter.. However, it invariably always messes the letter up by shifting the lettres in the last row of the letter forward so that they are not alligned with the rows above them thus screwing the A up. Similar alignment issues occur with the other letters.

I wanna know why this is happenign and how do I fix it..I cant seem to figure it out

Hack off the W and see if the rest displays properly. If it does, rework it to only need 80 columns.

how do rework it to be within 80 columns? Do i reduce the number of columns in the arrays?
 

sao123

Lifer
May 27, 2002
12,653
205
106
one of your problems i see is this...

you defined a 2D array...


char A[6][11]={
{" J"},
{" J"},
{" J"},
{" J"},
{"J J"},
{" JJ"}};



but failed to include the 2nd perameter when ouptutting

cout<<A[j];
 

jai6638

Golden Member
Apr 9, 2004
1,790
0
0
i must have copied an older version of my program or somethin.. My program currently does output both parameters

cout<<A[j];

thanks