I have a problem. I have a do while loop that go on foever. I want to stop it by pressing the enter button with out typing any input. How do i write the if statement ??
:0
I have a problem. I have a do while loop that go on foever. I want to stop it by pressing the enter button with out typing any input. How do i write the if statement ??
:0
The one & only!!
It's not standard, but you could try kbhit() (or _kbhit() or
__kbhit()!, depending on your compiler) which is in conio.h.
If it's in Windows then you could try checking GetAsyncKeyState()
during it iteration of the loop.
Code:do { if(kbhit()) { keypress=_getch(); if(keypress==13) break; } }while(whatever);
I get an error when i input the code:
error C2065: 'keypress' : undeclared identifier
Error executing cl.exe.
do
{
cout << endl
<< "Enter employee last name: ";
cin >> lastname[count];
cout << endl
<< "Enter ssn: ";
cin >> ssn[count];
count++;
if(kbhit())
{
keypress=_getch();
if(keypress==13)
break;
}
} while (count < 50);
//Maximum employees is full
if (count == 50)
cout << endl << "Maximum employees for database is reached." << endl;
system ("CLS");
The one & only!!
i was just making up a variable name. first you must declare it:
int keypress;
ok the program is executeable BUT
when i press enter nothing happens. it doesnt clear the screen & take me to the report screen?
The one & only!!