Hacking remember the guy .......

arjaylight

Well-Known Member
OP
Newcomer
Joined
Jun 17, 2009
Messages
65
Trophies
1
XP
201
Country
i believe || is short-circuit "OR" while | is the regular "OR"

|| is better (i think) because once it found a true value, it will automatically do the statement body and skips other conditions.
 

giantpune

Well-Known Member
Member
Joined
Apr 10, 2009
Messages
2,860
Trophies
0
XP
213
Country
United States
i didnt play it since it is windows game, but i took a quick look at main.cpp. you use
Code:
else if((answer==1)|(answer==2))
many times. do you mean "||" ? there are different "or"... "|" and "||" mean different things.


and when you get the person's name, you use
Code:
char name[15];
im not sure how the memory nanny in windows is, but what happens when you enter a name that is too long? i think you may fill up the buffer like the twilight hack did and maybe run into trouble.
 

Joe88

[λ]
Global Moderator
Joined
Jan 6, 2008
Messages
12,736
Trophies
2
Age
36
XP
7,427
Country
United States

arasium

Well-Known Member
Member
Joined
Mar 19, 2009
Messages
187
Trophies
0
Location
Paris
Website
Visit site
XP
98
Country
France
The real difference between | and || is that this first one is a bit operation and the second one is a logical operation.


In fact, in c/c++, a statement is true when the result is different from 0. So when you use ==, the program is doing something like that:

int is_equals(int a, int b) wich return 0 if not equal.

So when you use |, the result will be a bitwise OR and if one of the operand is different from 0, the result will be different from 0 => If one of the operand is "true" the result will be "true". So, the program will run perfectly.

But like someone said, it's better to use ||, because using that, the program won't do the same. He will check the second value only if the first is "false". In ASM, you will have a pseudo code like that:

if(a || b) =>

Code:
IF a != 0
ÂÂGOTO EXEC

IF b != 0
ÂÂÂÂGOTO EXEC

GOTO ENDIF

EXEC:
ÂÂyour code

ENDIF:
ÂÂthe rest of the prog

And with if( a | b) =>

Code:
C = A | B
IF C == 0
ÂÂGOTO ENDIF

your code

ENDIF:
ÂÂthe rest of your code
 

Wiimm

Developer
Member
Joined
Aug 11, 2009
Messages
2,292
Trophies
1
Location
Germany
Website
wiimmfi.de
XP
1,519
Country
Germany
Use tables, parameters and return values. Using to much global parameters make the code confusing and incluides side effects. For example I have rewritten ques_toons():

CODEvoid ques_toons ( int & numsleft, int num1, int & mast )
{
ÂÂÂÂstatic const char * que_tab[] =
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂ0,
ÂÂÂÂÂÂÂÂ" What is the character SpongeBob's lastname ?\n\n"
ÂÂÂÂÂÂÂÂ" What is the first name of the person that always says wascally wabbits ?\n\n"
ÂÂÂÂÂÂÂÂ" What is the name of Popeye's son ?\n\n"
ÂÂÂÂÂÂÂÂ" From The Flintstone's, What is Barney's lastname ?\n\n"
ÂÂÂÂÂÂÂÂ" In the Smurf's, What was the name of the only female Smurf ?\n\n"
ÂÂÂÂÂÂÂÂ" What is the name of the dog in the cartoon Garfield ?\n\n"
ÂÂÂÂÂÂÂÂ" Who is Wiley Coyote always chasing around the desert ?\n\n"
ÂÂÂÂÂÂÂÂ" In the moive The Rats of nihm, Where did the rats live ?\n\n"
ÂÂÂÂÂÂÂÂ" Who is the FAT kid from Southpark ?\n\n"
ÂÂÂÂÂÂÂÂ" From the Smurf, Who is always chasing the Smurfs and tring to eat them ?\n\n"
ÂÂÂÂ};
ÂÂÂÂ
ÂÂÂÂif ( num1 > 0 && num1 < sizeof(que_tab)/sizeof(*que_tab) )
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂcout
 

cracker

Nyah!
Member
Joined
Aug 24, 2005
Messages
3,619
Trophies
1
XP
2,213
Country
United States
Wiimm said:
Use tables, parameters and return values. Using to much global parameters make the code confusing and incluides side effects. For example I have rewritten ques_toons():

CODEvoid ques_toons ( int & numsleft, int num1, int & mast )
{
ÂÂÂÂstatic const char * que_tab[] =
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂ0,
ÂÂÂÂÂÂÂÂ" What is the character SpongeBob's lastname ?\n\n"
ÂÂÂÂÂÂÂÂ" What is the first name of the person that always says wascally wabbits ?\n\n"
ÂÂÂÂÂÂÂÂ" What is the name of Popeye's son ?\n\n"
ÂÂÂÂÂÂÂÂ" From The Flintstone's, What is Barney's lastname ?\n\n"
ÂÂÂÂÂÂÂÂ" In the Smurf's, What was the name of the only female Smurf ?\n\n"
ÂÂÂÂÂÂÂÂ" What is the name of the dog in the cartoon Garfield ?\n\n"
ÂÂÂÂÂÂÂÂ" Who is Wiley Coyote always chasing around the desert ?\n\n"
ÂÂÂÂÂÂÂÂ" In the moive The Rats of nihm, Where did the rats live ?\n\n"
ÂÂÂÂÂÂÂÂ" Who is the FAT kid from Southpark ?\n\n"
ÂÂÂÂÂÂÂÂ" From the Smurf, Who is always chasing the Smurfs and tring to eat them ?\n\n"
ÂÂÂÂ};
ÂÂÂÂ
ÂÂÂÂif ( num1 > 0 && num1 < sizeof(que_tab)/sizeof(*que_tab) )
ÂÂÂÂ{
ÂÂÂÂÂÂÂÂcout
 

SanGor

Witchhunter
Member
Joined
Aug 21, 2008
Messages
993
Trophies
0
Website
Visit site
XP
215
Country
United States
Alot of the code you have written could be coded simplier in the way people have already pointed out but I wanted to say on addtional thing, don't put function into header files as they directly inserted into the file which includes them so this will sooner or later cause you some trouble.

Also the idea of functions is to minimize code in cases some job has to be done more than once or with different values, making a function for a something which is just done once or just a few lines of static code isn't worth to be made a function. ( open() and open2() for example ).

It's also a good idea to keep the main.cpp simple, best would be only having the main() function in there.

I would use a 2D/3D array fo the questions/answers and I would do it like that:




CODEÂÂÂÂÂÂÂÂ...

ÂÂÂÂÂÂÂÂ#define MAX_QUESTIONS 2

ÂÂÂÂÂÂÂÂint select, answer;

ÂÂÂÂÂÂÂÂcin >> select;

ÂÂÂÂÂÂÂÂif( select >= MAX_QUESTIONS )
ÂÂÂÂÂÂÂÂÂÂÂÂfail();

ÂÂÂÂÂÂÂÂint CurrentQuestion=0;

ÂÂÂÂÂÂÂÂchar *Questions[2][2] = {
ÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"Who?",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"Where?",
ÂÂÂÂÂÂÂÂÂÂÂÂ},
ÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"When?",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"Why?",
ÂÂÂÂÂÂÂÂÂÂÂÂ},

ÂÂÂÂÂÂÂÂ};

ÂÂÂÂÂÂÂÂchar *Answers[2][2][2] = {
ÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"1. He",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"2. She",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ},
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"1. There",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"2. Here",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ},
ÂÂÂÂÂÂÂÂÂÂÂÂ},
ÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"1. Now",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"2. Later",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ},
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"1. Love",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ"2. Money",
ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ},
ÂÂÂÂÂÂÂÂÂÂÂÂ},

ÂÂÂÂÂÂÂÂ};


ÂÂÂÂÂÂÂÂwhile( CurrentQuestion < MAX_QUESTIONS )
ÂÂÂÂÂÂÂÂ{
ÂÂÂÂÂÂÂÂÂÂÂÂcout answer;
ÂÂÂÂÂÂÂÂÂÂÂÂDoCheck( select, answer );
ÂÂÂÂÂÂÂÂ}
 

scooby74029

wanttabe dev
Member
Joined
May 7, 2010
Messages
1,357
Trophies
1
Age
48
Location
oklahoma, USA
Website
www.wiithemer.org
XP
1,338
Country
United States
thanks for all of your help and the rewrites guys

i know i did somethings wrong but i have only gotten throught the first 5 chapters of this tutorial
http://www.cprogramming.com/tutorial/lesson1wrap.html

really again thanks for the help and i will reread this after work and start a rewrite soon

by the way if i knew more how to make structures and more about functions and arrays my game probly would not have been
so long. also if someone has the time to rewrite it properly i would like to see the proper way to do it

i mean with defines and functions that do something and return something. i couldnt find any small programs on the next to study how these things are put together.

well again thanks everyone
 

scooby74029

wanttabe dev
Member
Joined
May 7, 2010
Messages
1,357
Trophies
1
Age
48
Location
oklahoma, USA
Website
www.wiithemer.org
XP
1,338
Country
United States
bump:


hoping someone was on who might have time to help me out. i would like someone to take my program and rewrite it.

i am only just begining to learn so all i want is some functions that take args and return something so i can see how it is set up.

i guess i am not getting it...well all of it.

like i said earlier i am only 2 months into learning from a website. i am only up to switchcase and pointers now and still dont know how to use them very well as you will see in my program.
 

scooby74029

wanttabe dev
Member
Joined
May 7, 2010
Messages
1,357
Trophies
1
Age
48
Location
oklahoma, USA
Website
www.wiithemer.org
XP
1,338
Country
United States
well i looked over what cracker posted and all i can say is man mine was pooo compared to that.....

thanks alot cracker i will use it as an example for what ever i try next.

if anyone else would like to help me understand how to code efficiently and effectively.......
please send to me or post here or you can take the other cpp files and show me some suff with them.
i just want to learn.

thanks in advance to all helping.

and if this is not on topic please tell me where to go and i will and if admin would delete from here and put where it suppose to go
if they can?...idk new to most of this. i still hunt and peck at keyboard never learned to type until recently..
learning that too.....
 

Joe88

[λ]
Global Moderator
Joined
Jan 6, 2008
Messages
12,736
Trophies
2
Age
36
XP
7,427
Country
United States
I did make a 2 player tic tac toe game if you wanna look at that

a few other things like a gas pump emulator
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • No one is chatting at the moment.
    Sonic Angel Knight @ Sonic Angel Knight: :ninja: