Hi, im trying to creat tic tac toe game, but it is not working.
When i compile it, and i go past welcome message it only displays "1:"
after which program ceases to work as if return(0) was triggered;
Line 68: You don't save the result of calling check()
Should be:
1 2
a = check();
There is no need to pass a into check since you're passing it in by value, not reference and check doesn't need it.
Your if statements in check are defective. You're using the assignment operator, not the equality operator. Also, the comma is not appropriate.
Should be:
Line 68: You don't save the result of calling check()
Should be: a = check();
It returns me error called:
"error: too few arguments to function 'bool check(bool)'"
If i change it back the way it was, error is gone, but it still only gets to line 60, after i press enter, it only displays "1:" and whatever number is inputed afterwards, program terminates itself.
You don't need to pass it anything, as when you return from the function, you're saving the value in main. With the above statement, from AbstractionAction: a = check();
Thanks, it surely helps the code, but the output still isn't fixing anything at all.
Program still gives symtomps mentioned in my post above yours.
I think, maybe something is wrong with my cout ?
Yes! Thank you very much, it did indeed worked.
Last problem this program has is, after inputing anything, it doesent matter, becouse by default all fields are empty, therefore are the same, so immideatly when program has option to check for winners, it says player O won.
Any idea how to make it detect X and O only ? Ignoring the fact all fields are same, becouse they are empty ?
I know that, but if that's what i need to do, there will be ALOT of code as there will be practically twice as much code, becouse i need to insert same thing for O as i will for X.
I tried to make it switch between X and O so after player O inputs it checks for O's and after player's X turn it check's for X.
The first error I see, are lines 61 and 70.
The way you have them, looks like they should be within an if-statement etc.
assignment/equality!
And looking at your check function, it looks fine. Is there a problem with it?
Also, in that function, you don't need the else at the end, just return false, as none of the above statements returned true. (:
Edit:
I thought they were elseif statements! It only returns false, when the last if-statement is not true!
Yes! It finally works!
Magnificent, thank you very much, y'all helped alot, even if problems were so tiny yet had such influence on output!
Thanks for help! :)
I find goto very easy to use as i can jump quickly somewhere and put conditions with if's for jump if i need. They seem best kind of loop for me.
If you think gotos are easy, you've never had do debug a program with hundreds of gotos pointing backwards and forwards, and try and figure out how you got to a certain point in the code.
The problem with gotos is not where does it go, but rather "how did I get here"? Consider a program with 14 gotos that all jump to the same label. No way to tell how you got to the label. By comparison, a structured loop (while, do while, for) has an explicit entrance and an explicit exit. No question about the flow of the program.
As a programming manager, if I found one of my programmers using gotos instead of a structured loop, he wouldn't be working for me for very long. I'm not here to bash your code, but rather to try and illustrate why gotos are evil.
My advice, would be to use loops straight away, to get a better understanding of them.
Else, when you come to implement loops in bigger programs, you'll find yourself getting stuck.
And believe me, you will! I'm writing Tetris at the moment and a certain loop is kicking my ass, been trying to debug it for about an hour now. And the thing is, I know it's simple! ahaha
No. The use of gotos is the result of either being lazy, lack of coding discipline, not understanding structured programming, or not understanding how to code a proper loop. It doesn't matter if it is one goto or 100. It's still a bad practice.
You say you wouldn't use a goto in a big project. Well programs often start small and frequently morph in much bigger programs. At what point do you go back and recode your program to use proper loops rather than gotos? 10 gotos? 20? 100?
It's possible to create program flow using gotos that you can't easily convert to conventional loops. How much code are you going to have to redo? I don't pay programmers to redo their code. I expect it to be written correctly the first time.
The fact that you're trying to defend the use of goto tells me you don't get it.