Post: C++ help
06-03-2011, 01:03 AM #1
|C++|
< ^ > < ^ >
(adsbygoogle = window.adsbygoogle || []).push({}); Can you tell me why this:
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
{
cout<<table[d][i]<<".";
}
cout<< endl;
}
system("PAUSE");
}

looks like this You must login or register to view this content.

---------- Post added at 09:03 PM ---------- Previous post was at 08:43 PM ----------

edit: instead of cout the array of i and d i created b and f(inside the inner nest of the for loop) and i defined both as '.'. but now its all "j"(7 by 7 row of j). at least its not as ugly but its better
FINAL UPDATE: i fixed it now it works
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
{
table[d][i] = '.';
cout<<table[d][i];
}
cout<< endl;
}
system("PAUSE");
}

(adsbygoogle = window.adsbygoogle || []).push({});
06-03-2011, 03:04 AM #2
kiwimoosical
Bounty hunter
Originally posted by SLiiTH3R View Post
Can you tell me why this:
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
{
cout<<table[d][i]<<".";
}
cout<< endl;
}
system("PAUSE");
}

looks like this You must login or register to view this content.
---------- Post added at 09:03 PM ---------- Previous post was at 08:43 PM ----------

edit: instead of cout the array of i and d i created b and f(inside the inner nest of the for loop) and i defined both as '.'. but now its all "j"(7 by 7 row of j). at least its not as ugly but its better

I don't think this is right but you never filled the array with any data... Just sayin..
06-03-2011, 04:37 AM #3
Ritztro
I am a Game Developer
Originally posted by kiwimoosical View Post
I don't think this is right but you never filled the array with any data... Just sayin..


Ya that is write so it was just stuck with whatever is in it.
06-03-2011, 08:40 PM #4
|C++|
< ^ > < ^ >
yes i did in the update i made above in the thread, this is what it looks like now
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
{
char b = '.';
char f = '.';
cout<<table[b][f];
}
cout<< endl;
}
system("PAUSE");
}

so i did assign data to the array.
06-04-2011, 02:22 AM #5
Ritztro
I am a Game Developer
Wait what exactly are you trying to do? I want to try and do it so I can practice coding.
06-04-2011, 03:09 AM #6
kiwimoosical
Bounty hunter
Originally posted by SLiiTH3R View Post
yes i did in the update i made above in the thread, this is what it looks like now
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int x = 0;x<7;++x)
{
for(int y = 0;y<7;++y)
{
char b = '.';
char f = '.';
cout<<table[b][f];
}
cout<< endl;
}
system("PAUSE");
}

so i did assign data to the array.


You still never assign data to the array..
Try this:
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
table[0] = "testing";
table[1] = "racecar";
table[2] = "shithed";
table[3] = "hurrdur";
table[4] = "1234567";
table[5] = "7654321";
table[6] = "niqqerz";
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
cout<<table[b][f];
cout<< endl;
}
system("PAUSE");
}

The following user thanked kiwimoosical for this useful post:

XxprokillahxX
06-04-2011, 07:38 AM #7
Originally posted by SLiiTH3R View Post
Can you tell me why this:
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
{
cout<<table[d][i]<<".";
}
cout<< endl;
}
system("PAUSE");
}

looks like this You must login or register to view this content.

---------- Post added at 09:03 PM ---------- Previous post was at 08:43 PM ----------

edit: instead of cout the array of i and d i created b and f(inside the inner nest of the for loop) and i defined both as '.'. but now its all "j"(7 by 7 row of j). at least its not as ugly but its better


First of all, since your running a loop, its going to add a "." after each variable since you specified it in this code cout<<table[d]<<".";. Its adding all that junk because you had no values set for the array and its getting the text from the program ASCII code. If you were to remove the <<"." code part and add on top of the cout this: table[d] = 'a'; , then it will fix your problem. If this is not what you're looking for, then please tell me in depth of what you want your program to do.

Originally posted by another user
#include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
{
table[d] = 'a';
cout<<table[d];
}
cout<< endl;
}
system("PAUSE");
}
06-04-2011, 02:02 PM #8
kiwimoosical
Bounty hunter
Originally posted by MoBaTeY View Post
First of all, since your running a loop, its going to add a "." after each variable since you specified it in this code cout<<table[d]<<".";. Its adding all that junk because you had no values set for the array and its getting the text from the program ASCII code. If you were to remove the <<"." code part and add on top of the cout this: table[d] = 'a'; , then it will fix your problem. If this is not what you're looking for, then please tell me in depth of what you want your program to do.

That doesn't fix his problem, that just make everything equal to a. I gave the solution in the post above your's Smile
06-04-2011, 04:53 PM #9
|C++|
< ^ > < ^ >
aren't you like 1337 at c++???why would you need practice?? lol i guess you had me fooled.ps its supposed to be a dungeon crawler game, you'G' has to get to the end 'X' and avoid enemies'T' that are constantly changing move by move

---------- Post added at 12:44 PM ---------- Previous post was at 12:34 PM ----------

naaah all i had to do is say table[d]= '.'; then cout it. now it all comes out as dots like i wanted it to.

---------- Post added at 12:47 PM ---------- Previous post was at 12:44 PM ----------

Originally posted by kiwimoosical View Post
You still never assign data to the array..
Try this:
    #include <cstdlib>
#include <iostream>

using namespace std;

int main()
{
char table[7][7];
table[0] = "testing";
table[1] = "racecar";
table[2] = "shithed";
table[3] = "hurrdur";
table[4] = "1234567";
table[5] = "7654321";
table[6] = "niqqerz";
for(int d = 0;d<=7;++d)
{
for(int i = 0;i<7;++i)
cout<<table[b][f];
cout<< endl;
}
system("PAUSE");
}


no that is pointless all i had to do was set table[d] = '.', then cout it and it all comes out as dots

---------- Post added at 12:53 PM ---------- Previous post was at 12:47 PM ----------

no he is correct that is what i was looking for, im not trying to define every thing in the array im not dumb, but thank you for trying to help
06-04-2011, 07:23 PM #10
kiwimoosical
Bounty hunter
Originally posted by SLiiTH3R View Post
aren't you like 1337 at c++???why would you need practice?? lol i guess you had me fooled.ps its supposed to be a dungeon crawler game, you'G' has to get to the end 'X' and avoid enemies'T' that are constantly changing move by move

---------- Post added at 12:44 PM ---------- Previous post was at 12:34 PM ----------

naaah all i had to do is say table[d]= '.'; then cout it. now it all comes out as dots like i wanted it to.

---------- Post added at 12:47 PM ---------- Previous post was at 12:44 PM ----------



no that is pointless all i had to do was set table[d] = '.', then cout it and it all comes out as dots

---------- Post added at 12:53 PM ---------- Previous post was at 12:47 PM ----------

no he is correct that is what i was looking for, im not trying to define every thing in the array im not dumb, but thank you for trying to help


Oops, mis-understood your problem, thought you were stupid, s0zzz :P

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo