This:
Code:
printf("Ready to go? Y/N\n");
scanf(yn)
is a compile error, but if you meant:
There will be a '\n' left in the stdin buffer afterward, which may have consequences in the first iteration of your loop.
This:
Code:
for (int y = 0; y < 10; y++)
would only be valid under c99. It's also problematic because you have redeclared an identifier (y).
This:
Code:
getchar(a); // read a char from user
// exit loop if user hits enter
if (a == '\n')
break;
Is not a legal getchar() call, and 'a' is not declared anywhere. In short your code is not compilable for a number of reasons, which would explain why you "cannot seem to get what [you] want". You need to start with some working code, eg:
Code:
#include <stdio.h>
int main() {
printf("Ready to go? Y/N\n");
return 0;
}
And make sure it still compiles and runs when you add something new. Bonus point if it actually does what you want/expect.
Originally Posted by
dwilliams
Yes the compiler is of course yelling at me
That's like "go to jail" in monopoly. Do not pass GO. Do not collect $200.
but I am having trouble understanding the concept of how the user can break the for loop.
It will not be possible for you to come to an understanding if you can't write compilable code. First, it has to run. Then you can try and make it run the way you want. Not the other way around. Otherwise you might as well just use:
Code:
break here if the user wants to;
Makes sense...but the compiler will yell Do not pass GO, do not collect...
Code:
Inside the loop I want the program to count to ten seconds then beep (\a). I want it to keep on doing this until the user presses a key.
I don't know how many consoles will actually beep, don't be surprised if it doesn't -- that's kind of an atavism. WRT to timing, you can do this with sleep(), but it is a non-standard function and its definition differs from implementation to implementation (eg, on linux the parameter is in seconds, on windows in milliseconds).