Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/ / Function to ask a question bool ask _ question ( int max _ num ) { int num 1 = generate _ number
Function to ask a question
bool askquestionint maxnum
int num generatenumbermaxnum;
int num generatenumbermaxnum;
int answer, useranswer;
printfWhat is d d num num;
scanfd &useranswer;
answer num num;
if useranswer answer
printfCorrect
;
return true;
else
printfIncorrect
;
return false;
int main
srandtimeNULL; Initialize random seed
int difficulty, lives, maxnum, questions, score ;
printfWelcome
;
printfSelect difficulty:
;
printf Easy
;
printf Medium
;
printf Hard
;
Prompt the user until a valid difficulty is selected
do
printfEnter your choice or : ;
scanfd &difficulty;
while difficulty difficulty ;
Set variables based on difficulty
switch difficulty
case :
lives ;
maxnum ;
questions ;
break;
case :
lives ;
maxnum ;
questions ;
break;
case :
lives ;
maxnum ;
questions ;
break;
Loop through questions
for int i ; i questions; i
printfQuestion d of d You have s remaining.
i questions, lives life" : lives";
Check if it's the challenge question
if i questions
printfChallenge question!
;
if askquestionmaxnum
lives ;
break;
else
if askquestionmaxnum
lives;
if lives
printfOut of lives, game over!
;
break;
else
score;
Calculate percentage
int percentage score questions;
Print test complete message
printfTest complete!
;
printfYou scored dd d
score, questions, percentage;
Print grade
if percentage
printfGrade: High Distinction
;
else if percentage
printfGrade: Distinction
;
else if percentage
printfGrade: Credit
;
else if percentage
printfGrade: Pass
;
else
printfGrade: Fail
;
return ;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started