$ g++ -W{all,extra,pedantic} foo.cpp
|| foo.cpp: In function ‘int play()’:
foo.cpp|117 col 29| warning: statement has no effect [-Wunused-value]
|| board[counting+1];
foo.cpp|120 col 1| warning: no return statement in function returning non-void [-Wreturn-type]
|| foo.cpp: In function ‘int boards()’:
foo.cpp|151 col 1| warning: no return statement in function returning non-void [-Wreturn-type]
you should resolve those warnings.
Running through a debugger (user input is marked with >)
$ gdb a.out
(gdb) run
Starting program: /datos/ne555/documentos/informatica/test/forum/a.out
G = = = = T T = = T
= = = T T T = = T T
= T T = = = = = T =
= = = T T T = T T =
= = = T T = T = = =
= = = = T = = T = T
= = = = = = = = = =
= = = = = = T = = =
= = = T = = = = = =
= = = T = T = = = X
> d
> <C-c>
Program received signal SIGINT, Interrupt.
0x00007ffff7275510 in __read_nocancel () from /usr/lib/libc.so.6
(gdb) backtrace
#0 0x00007ffff7275510 in __read_nocancel () from /usr/lib/libc.so.6
#1 0x00007ffff720dad0 in __GI__IO_file_underflow () from /usr/lib/libc.so.6
#2 0x00007ffff720ebd2 in __GI__IO_default_uflow () from /usr/lib/libc.so.6
#3 0x00007ffff72095b0 in getc () from /usr/lib/libc.so.6
#4 0x00007ffff7b3edfd in __gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >::syncgetc (
this=0x7ffff7dd6680 <__gnu_internal::buf_cin_sync>)
at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/stdio_sync_filebuf.h:225
#5 __gnu_cxx::stdio_sync_filebuf<char, std::char_traits<char> >::uflow (
this=0x7ffff7dd6680 <__gnu_internal::buf_cin_sync>)
at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/ext/stdio_sync_filebuf.h:141
#6 0x00007ffff7b4c826 in std::basic_streambuf<char, std::char_traits<char> >::sbumpc (this=<optimized out>)
at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/streambuf:325
#7 std::istream::get (this=0x6022c0 <std::cin@@GLIBCXX_3.4>)
at /build/gcc/src/gcc-build/x86_64-pc-linux-gnu/libstdc++-v3/include/bits/istream.tcc:247
#8 0x0000000000400a49 in _getch () at foo.cpp:24
#9 0x0000000000400d5e in play () at foo.cpp:104
#10 0x0000000000400a34 in main () at foo.cpp:21
(gdb) frame 9
#9 0x0000000000400d5e in play () at foo.cpp:104
104 key = _getch();
(gdb) list
99 }
100 else if(key=='d')
101 {
102 while(counting+1>0)
103 {
104 key = _getch();
105 }
106 if(board[counting+1]==trap)
107 {
108 system("CLS");
There you see
102 103 104 105
while(counting+1>0)
{
key = _getch();
}
there is nothing in the body of the loop that may change the condition, so infinite loop. It will ask over and over again for input
By the way, ¿what were you thinking when writting lines 141--150?
you can use a loop there.