Assume that ncurses header is there and that my random_number_generator()
method is working. I am trying to exit the loop by hitting 'a' (eventually I want to exit by hitting CtrlE).
My code continues to print random numbers every second as intended. I want it to exit if either condition is met:
It will exit if the random number is a multiple of the divisor.
It will exit if I use
getch()
. I think this should work but it is not exiting when I hit a.int main(int argc, char *argv[]){ int lowest = atoi(argv[1]); int highest = atoi(argv[2]); int divisor = atoi(argv[3]); int random_number; srand((unsigned)time(0)); int c; do { random_number = random_number_generator(lowest, highest); cout << random_number << endl; sleep(1); } while(random_number % divisor != 0 || (c=getch())!=49); return 0; }
Edit:
I tried changing the condition to && instead but getch still does not let it exit:
Random number outputs range 1-10:
4
a3 <-hit a
aaa4 <-hit a many times
5 <-exits
Because
random_number % divisor != 0
is true thats why it does't care whatever you enteruse
&&
instead