You have to implement these functions: void seed_random(); int choose_random(int
ID: 3657521 • Letter: Y
Question
You have to implement these functions: void seed_random(); int choose_random(int min, int max); bool continue_quiz(); bool check_user_answer(int correct_answer, int user_answer); This is what should be shown when running the program: Example: Enter a min and max value for testing: 1 12 Enter a seed: 10 Would you like to continue the quiz? Type y for yes or any other key for no: y Problem 1 Try 1: 8x5 = 40 You got the right answer! Would you like to continue the quiz? Type y for yes or any other key for no: y Problem 2 Try 1: 3x6 = 10 Try again! Try 2: 3x6 = 12 Try again! Try 3: 3x6 = 20 Try again! Try 4: 3x6 = 18 You got the right answer! Would you like to continue the quiz? Type y for yes or any other key for no: n You solved 2 problems correctly!Explanation / Answer
#include #include //for bool type void seed_random(); int choose_random(int min, int max); bool continue_quiz(); bool check_user_answer(int correct_answer, int user_answer); int main(){ int min,max; int problemCount=0, NumCorrect=0; int tries, answer, a,b,c; bool contin=false,correct=false; printf("Enter a min and max value for testing: "); scanf("%d",&min); scanf("%d",&max); seed_random(); contin=continue_quiz(); while(contin==true){ tries=0;//reset tries to 0 a=choose_random(min,max);//get rand number b=choose_random(min,max);//get rand number c=a*b;//this is expected answer do{ tries++;//increment tries printf(" Problem %d Try %d: %dx%d = ",problemCount+1,tries,a,b);//output problem scanf("%d",&answer); correct=check_user_answer(c,answer);//check if correct if(correct==true){ //if correct printf("You got the right answer! "); //output this message tries=0; //reset tries problemCount++; //and increment problemCount, NumCorrect NumCorrect++; } else printf("Try again! "); //if wrong , output this }while(correct!=true);//loop until correct contin=continue_quiz();//ask user to continue } printf(" You solved %d problems correctly!",NumCorrect);//output number answered correctly getch();//get one key press return 0; } void seed_random(){//seed rand int seed; printf("Enter a seed: "); scanf("%d",&seed); srand(seed); return; } int choose_random(int min, int max){ return rand()%(max-min) +min; } bool continue_quiz(){//return true if 'y' or 'Y' entered, false otherwise char choice='n'; printf(" Would you like to continue the quiz? Type y for yes or any other key for no: "); scanf(" %c",&choice); //note that ther eis a space before %c, it's to ignore the newline/whitespace from last %d read if(choice=='y'||choice=='Y'){ return true; } else return false; } bool check_user_answer(int correct_answer, int user_answer){//return true if correct, otherwise false if(correct_answer==user_answer) return true; else return false; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.