I am trying to write a program that goes through a loop while the user holds down the [ENTER] key and EXIT the loop when the key is no longer depressed.
I got the first part, the loop cycles while the key is depressed but the program just stops when the user no longer holds down the [ENTER] key.
I’m not even sure it’s possible. Thank you!
I got the first part, the loop cycles while the key is depressed but the program just stops when the user no longer holds down the [ENTER] key.
I’m not even sure it’s possible. Thank you!
Code:
double a = 0; double b = 3.5; double c = 0; char ch; ; cout << " PRESS ENTER KEY "; ch = cin.get(); while(ch) { ch = cin.get(); c = a * b; a = a + 0.01; cout << "\n TOTAL = " << c; if (ch = !cin.get()) // THIS DOESN’T WORK { break; } } cout << "\n FINISHED"; cout << "\n TOTAL = " << c
Comment