#include <iostream.h>;
#include<conio.h&ht;
int main()
{
char c=getch();
while(c != 27)//27 means escape
{
switch(c){
case 'a':
cout << "you hit a" << endl;
break;
}
}
return(0);
}
//tell me what each thing means please!
#include <iostream.h>;
#include<conio.h&ht;
int main()
{
char c=getch();
while(c != 27)//27 means escape
{
switch(c){
case 'a':
cout << "you hit a" << endl;
break;
}
}
return(0);
}
//tell me what each thing means please!
Getch takes a single character input. That input is stored into a char and compared with c. If it is a c, then the output is displayed. Whats the deal?
<PS: Don't put semi-colons after #include statements>
I made a few changes to the program to get it to work correctly but it will display you hit a when an a is entered. If anything else except an esc (escape) is entered it will do nothing but get the next character from the console. If an escape is entered it exits.
Code:#include <iostream.h>//removed the ; #include<conio.h> //removed the ; int main() //entry point for the program { char c = ' ';//initialize c to a space while(c != 27)//27 means escape { //while c not equal to an escape repeat the follow intructions c = getch(); //get a character from the console switch(c)// test the value of c { case 'a': //if c = a not a and A only a then print cout << "you hit a" << endl; break; //end of 'a' } } return 0;// return 0 to caller }
If 27 means escape, what is left, right, up and down?
easier explanation for above: where do you find out?
check out scan codes and ascii codes... you can detect arrow [and other special] keypresses using scan codes... there is an interrupt which returns each, i'll find my input routine and give you it here in time... but that's a start until i return...
hasafraggin shizigishin oppashigger...
where do you find the scan codes or the ascii codes?
a textbook is one place. You could try writing a program too, at least for the ASCII codes.
for(int i = 0; i < 256; i++)
cout << " the integer " << i << " = " << (char)i << endl;
i realized i had to edit it a lot... [must choose 'save tabs as spaces' in my editor...] hehe... any ?uestions? it returns the scan code in the high order byte, and the ascii in the low order byte of a 16-bit unsigned word... [short]Code:// scan code, then ASCII code unsigned int KF :: k_chk___ (vo) // SCAN CODE / ASCII check { __dpmi_regs io; // or whatever regs structure it is... if (kbhit ()) { // while (kbhit ()) // keep on getting a character / flush { io.x.ax = 0x00; __dpmi_int (0x16, &io); } if (io.h.al == 13) // if carriage return, return a 10 instead return ((io.h.ah<<8) | 0x000a); else // else return normal return ((io.h.ah<<8) + io.h.al); // SCAN CODE / ASCII } else { return (0x0000); } }
hasafraggin shizigishin oppashigger...