hey there...
i need to create a random numbers generator..
i solve the code already..
but.. how am i going to have my program keep on running..
for example:
"PRESS ANY KEY TO CONTINUE"
(then.. the program run from the beginning..)
hey there...
i need to create a random numbers generator..
i solve the code already..
but.. how am i going to have my program keep on running..
for example:
"PRESS ANY KEY TO CONTINUE"
(then.. the program run from the beginning..)
You should learn how to use the looping structure in C. You can just google it out.
i'd try to insert while repetition structure...
but, it cant be stop.. and "PRESS ANY KEY TO CONTINUE" isnt functioning..
Code:#include<stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int i; time_t t; srand((unsigned) time(&t)); while (i != 0) { printf("Printing 5 random numbers:\n"); for(i=0; i< 5;i++) printf("%d\n",rand()%100); printf("Press any key to continue..\n"); } }
Firstly you have never assigned i a value so you shouldnt be checking its value.
also, if you want your loop to go on forever, a better way would be -
while(1) or while(true)
Yes, The computer doesn't wait for a key press just because you printed it on the screen.and "PRESS ANY KEY TO CONTINUE" isnt functioning..
Cprogramming.com FAQ > How do I get my program to wait for a keypress?
got it!! thanks spidey!!
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
while (1) {
printf("Printing 5 random numbers:\n");
for(i=0; i< 5;i++)
printf("%d\n",rand()%100);
printf("Press any key to continue..\n");
}
}
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i;
time_t t;
srand((unsigned) time(&t));
while (1) {
printf("Printing 5 random numbers:\n");
for(i=0; i< 5;i++)
printf("%d\n",rand()%100);
printf("Press any key to continue..\n");
}
}
Is it correct?
That is correct, though not as correct as it could be with [code][/code] tags. In any event, you should also be aware that you could just as easily do
so that one actually has to press a key to continue.Code:#include<stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int i; srand((unsigned) time(0)); /* the pointer is an optional parameter */ while (1) { printf("Printing 5 random numbers:\n"); for(i=0; i< 5;i++) printf("%d\n",rand()%100); printf("Press any key to continue..\n"); getchar(); } }
wipe on -A slap on the hand is better than a slap on the face. A tragic lesson learned far too late in life.- wipe off