Thats the piece of code in question. Its not the problem. The problem is if the user enter letters it locks the program up so how do I stop them from entering letters?
#include <iostream>
#include <cctype>
usingnamespace std;
int main()
{
int x1;
cout << "enter a number :";
cin >> x1;
//if x1 is number, then 'yes' message will be printed out
if (!isdigit(x1))
{
cout << "yes" << endl;
exit(-1);
}
//but if it's not number, then 'no' message will be printed out
else
{
cout << "no" << endl;
}
}
[Session started at 2010-11-05 09:09:09 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May 5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys000
Loading program into debugger…
Program loaded.
run
[Switching to process 11478]
Running…
enter a number :a
yes
EDIT: And that's not all...
[Session started at 2010-11-05 09:11:12 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May 5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty" for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 11514]
Running…
enter a number :48
no
[Session started at 2010-11-05 09:11:12 -0700.]
GNU gdb 6.3.50-20050815 (Apple version gdb-1469) (Wed May 5 04:36:56 UTC 2010)
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB. Type "show warranty"for details.
This GDB was configured as "x86_64-apple-darwin".tty /dev/ttys001
Loading program into debugger…
Program loaded.
run
[Switching to process 11514]
Running…
enter a number :48
no
but I do know nosxlimits code did not work for me so what albatross is saying must be right im going to read that stuff he put links to.