Sep 17, 2008 at 1:21am UTC
How I can make the program react when someone press Y or N? I should use #define *Letter* (hexa code)
? If yes, what are their hex values?
Last edited on Sep 17, 2008 at 1:24pm UTC
Sep 17, 2008 at 1:55am UTC
use cin and if statements if thats all you need, its alot simpler than what uve got
Last edited on Sep 17, 2008 at 1:55am UTC
Sep 17, 2008 at 1:27pm UTC
You mean something like this: if (choice == "Y" )
?
Sep 17, 2008 at 2:37pm UTC
I tried use that, but I did get this error:
C:\Codes\C++\C++ Projects\YN.c|10|error: ISO C++ forbids comparison between pointer and integer|
C:\Codes\C++\C++ Projects\YN.c|12|error: ISO C++ forbids comparison between pointer and integer|
This is the code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#include <iostream>
using namespace std;
int main()
{
char choice;
cout << "Press Y or N" ;
cin >> choice;
if (choice == "y" )
cout << "You pressed Y!" ;
else if (choice == "n" )
cout << "You pressed N!" ;
else
cout << "..." ;
cin.get();
}
Last edited on Sep 17, 2008 at 2:40pm UTC
Sep 17, 2008 at 2:45pm UTC
"Y"
is an array of char
'Y'
is a char
choice is a char
Hope this helps.