Thread: C++ Character Game array
-
March 16th, 2009, 03:03 PM #1Junior 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;
}
-
March 19th, 2009, 06:35 PM #2
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
-
March 19th, 2009, 07:38 PM #3
how do you have 0 posts?
Intel Q6600 Quad Core Processor 2.4GHz
4Gb DDr3 1600 | Radeon HD4870X2 2Gb
Asus P5Q3 Deluxe Motherboard
-
March 25th, 2009, 05:07 PM #4Junior 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.
-
March 25th, 2009, 07:11 PM #5
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
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
What pre-1985 video game character are you?
By Toadman in forum IMO CommunityReplies: 33Last Post: February 27th, 2008, 05:45 AM -
what video game character are you?
By RedFury in forum General Gaming DiscussionReplies: 39Last Post: September 6th, 2004, 02:08 AM -
What Pre-1985 Video Game Character Are You?
By ClubMed in forum IMO CommunityReplies: 16Last Post: March 20th, 2002, 02:42 PM



LinkBack URL
About LinkBacks



Reply With Quote

Hi so I got my PC built for me I just selected parts but everything is installed on my (C: ) SSD. I understand that for performance Windows should be installed on that however all of the users are...
Full SSD Set files.