home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

C++ Character Game array

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2468
Discussions: 200,959, Posts: 2,379,551, Members: 246,329
Old March 16th, 2009, 04:03 PM   Digg it!   #1 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 1
C++ Character Game array

Hi, Im a some what intermediate programmer. I am having a problem with My character array.
When its filled with simple intliziers, it malfuntions, and is recreated each time. However, if i leave it empty, it works fine.

heres the code if you want to take a gander.
i applogize for the slight mess of my programming.

#include <iostream>
#include <string>
#include <fstream>
#include <stdlib.h>
using namespace std;


string Uname;
char Ans;
//int row= 5;
//int collum= 5;
void MANtable();
void MANtest();
//int testQuestions();
void HAppyMEssage();



char TablA[10][10];

int main()
{
cout <<" Welcome to Tia's Game for programming" << endl;
cout << " What is your name?" << endl;
cin >> Uname;

cout <<" Is " << Uname <<" your name? (y/n)" << endl;
cin >> Ans;
if (Ans == 'y')
{
cout <<" Very good, Your name is saved!" << endl;

}
else
{
cout <<" No? Please tell me again your name " << endl;
cin >> Uname;
}

int nCount = 0;
int Start = int(1);// smiley face!
int Mr = 0;
int Mc = 0;

while (Ans != 'U')
{



nCount++;
cout << nCount <<" I am the counter ";
MANtable();

cout <<" Where do you want to go? (ROW?) " << endl;
cin >>Mr;
cout <<" Where do you want to go ( COLLOUM?)" << endl;
cin >> Mc;
TablA[Mr][Mc]= 'M';


cout <<" Would you like to quit? (U to quit~!) " << endl;
cin >> Ans;
}

cout << "****************\n\n"<< endl;
HAppyMEssage();
/*MANtest();
testQuestions();*/
//



return 0;

}

void MANtable()
{
for ( int c= 0; c < 10; c++)
{
for (int r=0; r < 10; r++)
{

cout << TablA[c][r] ;
}
cout << endl;
}
cout <<" This is the manual test of the table"<< endl;
}


void MANtest()
{
// make a funciton that will pull out specifc numbers for the table, from there you should be able to make a table
// along the lines of the square that you see in page 480. Keep in mind that when you make a number that you want to use
// one minus the lenth.



for(int r= 0; r <10; r++)
{
for(int c=0; c < 10; c++)
{
TablA[r][c] = int(177);

/*1*/ if ( r== 0 || c== 1)
{
for( int PO = r; PO < 9; PO++)
{
TablA[PO][c] = '=';
}
}

/*2*/ if ( r== 7|| c== 4)
{
for (int T= r; T >0; T--)
{
TablA[T][c]= '=';
}
}
/*3*/ if ( r==2 || c == 9)
{
for (int E=c; E >0; E--)
{
TablA[E][c]= '=';
}
}
/*4*/ if (r==4 || c== 7)
{ for(int J= r; J<9; J++)
{
TablA[J][c]= '=';
}
}
TablA[2][0] = ' ';
TablA[2][1] = ' ';
TablA[2][2] = ' ';
TablA[3][2] = ' ';
TablA[4][2] = ' ';
TablA[5][2] = ' ';
TablA[5][3] = ' ';
TablA[5][4] = ' ';
TablA[5][5] = ' ';
TablA[5][6] = ' ';
TablA[6][6] = ' ';
TablA[6][7] = ' ';
TablA[7][7] = ' ';
TablA[7][8] = ' ';
TablA[8][8] = ' ';
TablA[9][8] = ' ';
// compleate pathway though maze is done.
// TablA[0][0] = 'M';// write to uper left i only print out an M

cout << TablA[r][c];
}
cout << endl;

}
//cout <<" Manual make of the tables that now has walls" << endl;


}









int testQuestions()
{
string line;
ifstream QuestionF ("testing.txt");
ofstream Wrong("Bad.txt");

if (!QuestionF)
{
cout <<" The file is bad!"<< endl;
return 1;

}


int R= 2;
int C= 0; // these two numbers create the starting point for the user to dance in my maze of death.
int count =1; // i am the count for the questions. delete and the Answers show.
string ANSWER;
string uA;

int Mr;
int Mc;// movign row and collum made by user.

while(! QuestionF.eof()&& uA!="Q")// I AM A WHILE LOOP! I READ IN FROM TEXT FILE, AND WHEN I HIT EOF OR USER IPUTS A 'Q' I STOP!
{
while( count <=6)
{
if ( count<= 5)
{ getline(QuestionF, line);
cout << line<< endl;}

if ( count== 6)
{
getline(QuestionF, ANSWER);
}
count ++;

}
cout << "What is your answer? type Q to quit" << endl;
cin>> uA;
cout << system("CLS")<< endl; // I READ IN QUESTIONS, I ALSO ASK FOR ANSWERS FROM USER!



int Start = int(1);// smiley face!



if( uA == ANSWER) // IF USER ANSWER IS CORRECT
{
cout <<" Where do you want to go? (ROW?) " << endl;
cin >>Mr;
cout <<" Where do you want to go ( COLLOUM?)" << endl;
cin >> Mc;
TablA[Mr][Mc]= Start;


}







//determine the answer from the user,
//keep track of wrong answers,
// move peice on board
// go back and repeat.



//clear the screen and redraw the board ( use system{"CLS"};


count= 1; // im a diffrent from above. I make sure the while loop for the EOF ends.

}


QuestionF.close();
Wrong.close();


}

void HAppyMEssage()
{
cout << "Welcome to C-Maze!\n"<<
"This program is designed to help you learn c++ programming,\n"<<
"while having fun at the same time."<<endl;


}
Uoko is offline   Reply With Quote
Old March 19th, 2009, 07:35 PM     #2 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
I'm sorry, you are not an intermediate programmer. And this code is more than a "slight mess".

While I've coded in C and C++ for over 15 years and this is C++ code, it is the most fragmented piece of code that I've ever seen in my career.

And you're telling me you got this to compile? Yeah, right
Rootstonian is offline   Reply With Quote
Old March 19th, 2009, 08:38 PM     #3 (permalink)
Senior Member
 
TimeDeatH's Avatar
 
Join Date: Apr 2008
Posts: 572
Send a message via MSN to TimeDeatH
how do you have 0 posts?
__________________
Intel Q6600 Quad Core Processor 2.4GHz
4Gb DDr3 1600 | Radeon HD4870X2 2Gb
Asus P5Q3 Deluxe Motherboard
TimeDeatH is offline   Reply With Quote
Old March 25th, 2009, 06:07 PM     #4 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 1
What do you mean, " dose it compile"
Yes it compiles fine, but the character array dose not display properly, aside it being compiled.
Uoko is offline   Reply With Quote
Old March 25th, 2009, 08:11 PM     #5 (permalink)
Caveat Emptor
 
Rootstonian's Avatar
 
Join Date: Mar 2005
Location: Out of my mind
Posts: 3,241
Send a message via AIM to Rootstonian
cout << TablA[r][c];

This line? The << operator does not know how to display the contents of an array; you need a loop to do this or override the << operator.

Yes, I'm sorry, it does compile fine...still messy as all get out though
Rootstonian is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads
Thread Thread Starter Forum Replies Last Post
What pre-1985 video game character are you? Toadman IMO Community 33 February 27th, 2008 05:45 AM
what video game character are you? RedFury General Gaming Discussion 39 September 6th, 2004 03:08 AM
What Pre-1985 Video Game Character Are You? ClubMed IMO Community 16 March 20th, 2002 02:42 PM


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (2976)
The disrespect of Obama by Russian .. (45)
Making Health Care Worse (181)
Wireless Televisions. (12)
CPU fan stops spinning randomly (10)
Regular Build (11)
windows 7 problem (7)
Laptop with wireless problem. (5)
windows vista security holes (13)
Is the PSU I received dead? (13)
Point and Shoot Camera Suggestions. (5)
Print spooler problem (16)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
Point and Shoot Camera Suggestions. (5)
CPU fan stops spinning randomly (10)
Is the PSU I received dead? (13)
Print spooler problem (16)
Nvidia GTX 260 problem (0)
windows vista security holes (13)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
Open With ..... Win7 (1)
webcam (0)
upgrade for hp a6101 (0)
Laptop with wireless problem. (5)
Modern Warfare 2: Who Bought It? (64)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)
My monitor won't turn on after instal.. (1)
Internet Lost (3)
Dept. of HS: NSA 'Helped' Develop Vis.. (16)
Ideal cheap graph card for PC-Gaming? (18)
radeon x850xt platinum & shader 3 (6)
Graphics Card Upgrade Question (4)
For Sale BFG GTX285 OC2 with 10 year .. (3)


All times are GMT -4. The time now is 10:58 AM.
TechIMO Copyright 2009 All Enthusiast, Inc.



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