Hi,
my problem is pretty much summarized in the title, following code:
I'm trying to write a diceroller for shadowrun as a little exercise with C. Now i played around a bit, commenting out stuff and changing conditions, and it seems the program skips the "a=getchar();" line, it immediately stops after asking for another go. I use Geany as an IDE(compiler didn't show any errors) under Ubuntu 10, and when i tried executing the code in Terminal it did exactly the same thing it did when executed directly from Geany.Code:#include <stdio.h> #include <stdlib.h> #include <time.h> int main () { char a; int DP;int x=1;int gcount = 0;int rolls = 0;int success = 0; do { /* initialize random generator */ srand ( time(NULL) ); printf("Bitte Dicepool eingeben\n"); scanf("%d",&DP); while ( x<=DP) { int random = (rand() % 6)+1; printf ("Ergebniss: %d\n",random); x++; if(random == 1) {gcount++;} else if(random == 6||random == 5) {success++; if(random == 6){x--;}} rolls++; } printf("\nErfolge:%d, 1en:%d",success,gcount); printf("\n Nochmal (j/n)? \n"); /*asks if the user wants to go again*/ a = getchar(); }while( a == 'j'); return 0; }
I hope this isn't too stupid a question,I'm pretty noobish with C.
Thanks for the time.