C++ Programming Help

New Member
💻 Oldtimer
Joined
Sep 8, 2002
Messages
2,278
Best answers
0
Location
Earth
I need a little help here. I'm a pretty n00b programmer taking a class in highschool (it's a crappy class cuz the books are old, we use CODEWARRIOR, we use macs - nuff said)

Anyways I started to work on a program of my own and I would like to get some kind of conditional statement that would be something like...

if (Class == "Monk").... blah blah, I tried it and it didn't work...anyways here's my program so far (I've been experimenting w/ stuff) The book for C++ we use talks alot about Strings using #'s and single characters but nothing like im trying to do! >.<

Code:
// Sean Kiles
// DA
// 324
// Refer To fig04_16.cpp

#include <York.h>

void classHandling( char * );

char CName[ 12 ], Class[ 7 ];
int STR, INT, WIS, CON, DEX, Insight;

int main()
{

	cout << "DDDDDDD" << endl;
	cout << "D      D               k  k" << endl;
	cout << "D      D               k k" << endl;
	cout << "D      D  a a     rrr  kk" << endl;
	cout << "D      D a   a   r     k k" << endl;
	cout << "DDDDDDD   a a a  r     k  k" << endl;

	SKIP_2;

	cout << "\t" << "      A" << endl;
	cout << "\t" << "     A A" << endl;
	cout << "\t" << "    A   A" << endl;
	cout << "\t" << "   AAAAAAA     g g    eee    sss" << endl;
	cout << "\t" << "  A       A   g   g  eeeee  s s" << endl;
	cout << "\t" << " A         A   g gg  e         s" << endl;
	cout << "\t" << "A           A     g   eeee  sss" << endl;
	cout << "\t" << "               ggg" << endl;

	SKIP_4;

	cout << "[ Enter The Following Information ]\n" << endl;

	cout << "CHARACTER NAME\n> ";
	// cin >> set( 12 ) >> CName;
	cin.getline(CName, 12, '\n');

	cout << "CLASS (Monk, Priest, Rogue, Warrior, Wizard)\n> ";
	// cin >> set( 7 ) >> Class;
	cin.getline(Class, 7, '\n');

	cout << "INSIGHT (1-99, 100 for Master)\n> ";
	cin >> setw( 3 ) >> Insight;

	cout << "STATS\n";
	cout << "\tStr> ";
	cin >> setw( 3 ) >> STR;
	cout << "\tInt> ";
	cin >> setw( 3 ) >> INT;
	cout << "\tWis> ";
	cin >> setw( 3 ) >> WIS;
	cout << "\tCon> ";
	cin >> setw( 3 ) >> CON;
	cout << "\tDex> ";
	cin >> setw( 3 ) >> DEX;
	
	classHandling( Class );

	return 0;
}

void classHandling( char *classPtr )
{
	for ( ; *classPtr != 'Monk'; classPtr++) {
		cout << CName << "\n" << *classPtr << "\n" << Insight << endl;
	}
}
 
New Member
Joined
Feb 1, 2002
Messages
553
Best answers
0
maybe you could try to post this in the Coding / Bug Report section, you would probably get more reply's there...and you could ofcourse try to pm one of the team's coders like PC Joe or harSens. And i can't program in C++ but i wanted some tutorials once so maybe this site can help: http://devcentral.iticentral.com/articles/C++/default.php

Good luck with finding an answer, and btw are you trying to create a game??
 
New Member
💻 Oldtimer
Joined
Sep 8, 2002
Messages
2,278
Best answers
0
Location
Earth
Thanks. No, I am not trying to create a game. I want to make a program for an MMORPG called Dark Ages.
 
Lost in space
Banned
💻 Oldtimer
Joined
Dec 1, 2002
Messages
2,725
Best answers
0
I think what you're looking for is the strcmp function. It compares two strings character by character until the characters differ, or until one of the strings ends (it reaches the null character), and returns a value of 0 if the strings are the same, <0 is string1 is less than string2, and >0 is string1 is greater than string2.
To check to see if the player was a Monk, I'd declare a string constant of "Monk", and then use strcmp. To use strcmp, make sure you #include <.string.h> (ignore the first period, I did that so it'd show up)
Code:
#include <.string.h>

char Monk[5] = "Monk";

if (strcmp (Class,Monk) = 0)
     //Class is Monk, do what you want here.
Hopefully that was what you were looking for. ;)
 
New Member
💻 Oldtimer
Joined
Sep 8, 2002
Messages
2,278
Best answers
0
Location
Earth
Ooh, damn, I never thought of using something so damned obvious >.< thanks.

Okay, I made the changes (York.h has tons of C++ #includes, string.h being one of them) but when I run it I get an error...

Error : not an lvalue
DA_SSTestX.cpp line 64 if (strcmp (Class,Monk) = 0)
Here's the code with the changes...

Code:
// Sean Kiles
// DA Character Manager

#include <York.h>

char CName[12], Class[7],
	 Monk[5] = "Monk",
	 Priest[7] = "Priest",
	 Rogue[6] = "Rogue",
	 Warrior[8] = "Warrior",
	 Wizard[7] = "Wizard";


int STR, INT, WIS, CON, DEX, Insight;

int main()
{

	cout << "DDDDDDD" << endl;
	cout << "D      D               k  k" << endl;
	cout << "D      D               k k" << endl;
	cout << "D      D  a a     rrr  kk" << endl;
	cout << "D      D a   a   r     k k" << endl;
	cout << "DDDDDDD   a a a  r     k  k" << endl;

	SKIP_2;

	cout << "\t" << "      A" << endl;
	cout << "\t" << "     A A" << endl;
	cout << "\t" << "    A   A" << endl;
	cout << "\t" << "   AAAAAAA     g g    eee    sss" << endl;
	cout << "\t" << "  A       A   g   g  eeeee  s s" << endl;
	cout << "\t" << " A         A   g gg  e         s" << endl;
	cout << "\t" << "A           A     g   eeee  sss" << endl;
	cout << "\t" << "               ggg" << endl;

	SKIP_4;

	cout << "[ Enter The Following Information ]\n" << endl;

	cout << "CHARACTER NAME\n> ";
	// cin >> set( 12 ) >> CName;
	cin.getline(CName, 13, '\n');

	cout << "CLASS (Monk, Priest, Rogue, Warrior, Wizard)\n> ";
	// cin >> set( 7 ) >> Class;
	cin.getline(Class, 8, '\n');

	cout << "INSIGHT (1-99, 100 for Master)\n> ";
	cin >> setw(3) >> Insight;

	cout << "STATS\n";
	cout << "\tStr> ";
	cin >> setw(3) >> STR;
	cout << "\tInt> ";
	cin >> setw(3) >> INT;
	cout << "\tWis> ";
	cin >> setw(3) >> WIS;
	cout << "\tCon> ";
	cin >> setw(3) >> CON;
	cout << "\tDex> ";
	cin >> setw(3) >> DEX;
	
	if (strcmp (Class,Monk) = 0)
		cout << "w00t It w0rk3d!" << endl;

	return 0;
}
 
Lost in space
Banned
💻 Oldtimer
Joined
Dec 1, 2002
Messages
2,725
Best answers
0
Whoops, I used the assignment operator instead of the equality operator, my bad!
Replace
Code:
if (strcmp (Class,Monk) = 0)
with
Code:
if (strcmp (Class,Monk) == 0)
and it should work fine. :D
 
New Member
💻 Oldtimer
Joined
Sep 8, 2002
Messages
2,278
Best answers
0
Location
Earth
LoL, it's always small n simple things I overlook.

Thanks again DD
 

Users who are viewing this thread

Top Bottom