I want to generate a number in a given range as in the code below. However i get that i'm giving invalid operands to the modulus operator.isn't rand1 of type float already. What operands can i give it so i can return int the range of random 0 - rand1?Code:int divide(){ while(TRUE) { float rand1 = (correct > 11) ? ( rand() % 1000 + 1) : ( rand() % 100 +1); float rand2 = (correct > 11) ? ( rand() % rand1 + 1): ( rand() % rand1 +1 ); float r_ans; float ans; Prob+=1; /* if top number less than bottom number then switch numbers rand1 = (rand1 < rand2) ? rand2 : rand1; rand2 = (rand1 < rand2) ? rand1 : rand2; */ r_ans = rand1 / rand2; system("CLS"); title(); printf("To exit press any letter\n\n"); printf("Problem: %d\nCorrect: %d\nWrong: %d\nGrade: %.1f\n\n",Prob, correct, wrong, ((float)correct/Prob) * 100); /* later add correct updating into system("title") bar */ printf("What is the Quotient. Answer as N.N Ex: 1. 0 :\n\n "); printf("%4.1f Dividend\n", rand1); printf(" ----\n"); printf("%5.1f Divisor\n_____\n", rand2); while ( (scanf(" %f", &ans) ) ==1){ if (ans == r_ans){ correct +=1; printf("Correct!\n"); /* if ( (correct % 2 == 0 && wrong <= 3)){ puts("Your not bad at this."); } */ system("pause"); divide(); } else { wrong+=1; printf("Incorrect the answer is %.1f\n", r_ans); /*if ( (wrong % 5 == 0 && correct < 10) ){ puts("Your Math kung-fu sucks. You need more training"); } */ system("pause"); divide(); } }return EXIT_SUCCESS; } }



LinkBack URL
About LinkBacks



[/edit]