Something is wrong with my code?

closed account (LN3RX9L8)
The following is a game of battleship, but after a few rounds it stops completely and only displays the battle ship... I don't know what the problem is with my code that is making it do this. Can someone give me advice? I would really appreciate it and thanks!

Last edited on
This would be a great time for you to learn how to use a debugger - it will let you step through your code and see how the variables change as the program runs.
closed account (LN3RX9L8)
@LB I actually did use a debugger r but removed it from the code when I posted it here
Debuggers don't change your code at all, they're a tool that come either with your IDE or independently. If you had something to change in your code, it was not a debugger.
closed account (3CXz8vqX)
....apparently I'm not the only one who thinks... .>.>; *ducks*.

Load up Code::Blocks or your favourite IDE, I'm highly recommending Code::Blocks for its functionality, it has a debug section at the top.

You *could* do things manually with a debug variable and check every line of code that way, much like throwing errors. So take for instance checking a for loop, I'd use this code.

1
2
3
4
for (int i=0; i<4; i++)
{
    if(debug) cout << i;
}


That tells me the value of I and how it is progressing. I'd advise specifically to check the logic, especially when using != ...it inverts almost everything.

With an IDE, things are made much more simpler and less labour intensive, just take a look at the Debug menu. A 'debugger' as L B is inferring to, is a tool not a process (like how I was taught in Java (I note this contradicts a previous statement I've made)...but never mind).
Ravenshade wrote:
much like throwing errors
Stop making up your own terminology when communicating with others. You throw exceptions, not errors.
closed account (3CXz8vqX)
Oh ffs. Stop nitpicking, it's pretty obvious given the context what I was referring to. That said, when a compiler displays an error, I call it "throwing a wobbly"... so throwing an error not a stretch.
Last edited on
closed account (LN3RX9L8)
Okay thanks guys! I tried it and didn't work... Do you guys have Xcode or the other one to run my code and see what happens?
Ravenshade wrote:
I call it "throwing a wobbly"... so throwing an error not a stretch.
I'm not kidding, you can't just make up terminology on the spot. The compiler generates errors and code can throw exceptions. The latter is because you actually use the keyword "throw" and the class is actually called std::exception.
De Morgan
1
2
3
4
5
6
7
8
//what you wrote
row!=indexrow && column!=indexcolumn
row not_eq indexrow and column not_eq indexcolumn
not( row==indexrow or column==indexcolumn )

//what you intended to write
not( row==indexrow and column==indexcolumn )
row not_eq indexrow or column not_eq indexcolumn

Why would you report that? It's important to use proper terminology in programming. There are plenty of programmers who can not speak English well, and will get confused if you just throw in your own slang. Programming is far from non-demanding when it comes to vocabulary.
closed account (3CXz8vqX)
It's offtopic and thread cleaning. (this place really needs a pm system). edit. I've also requested my own posts be removed for the same reason.

Also, in addition to ne555

!( row == indexrow && column==indexcolumn) should also work.
Last edited on
closed account (LN3RX9L8)
you can place a '!' outside the brackets?? Where would I place this line of code
closed account (3CXz8vqX)
Line 58.

if( !( ( row == indexrow ) && ( column==indexcolumn ) ) ) { // do stuff }

...C++ is awash with these little weird bits...

edit: I like my brackets...
Last edited on
closed account (LN3RX9L8)
@Ravenshade wow you are a genius Thanks so much!!!! It works!! but what exactly does that line of code do?? I set it up to check if the user guesses the battleship they would win... but now it's saying ?? Can you explain this thanks!
Last edited on
@Ravenshade those "weird bits" are nested expressions ;)
closed account (3CXz8vqX)
I meant the tweaks like if(! function()).... and throwing the different equations into different orders. Just wait until the Op finds out about overloading operators.... >-<;
Stroustrup said he's not happy with the operator precedence in C++, but ht'e stuck with it from C and for compatibility, etc.
Topic archived. No new replies allowed.