I have written this code and it will work with an interger but not a float. I have tried casting but it does not run correctly. I want to pause for 0.5 seconds when each line prints. Here is the code:
Code:
#include <stdio.h>
#include <time.h>
int main() {
int n = 1;
char fz[] = "Fizz";
char bz[] = "Buzz";
char fb[] = "FizzBuzz";
float sec = 0.5;
for ( n = 1; n < 101 ; ++n )
if ( n % 15 == 0 ) {
printf("%s\n", fb);
sleep((int)sec);
} else if ( n % 5 == 0 ) {
printf("%s\n", bz);
sleep((int)sec);
} else if ( n % 3 == 0 ) {
printf("%s\n", fz);
sleep((int)sec);
} else {
printf("%d\n", n);
sleep((int)sec);
}
return 0;
}
If I change the function line to sleep(1); it works but is a bit slow.