modify Exercise 6.57 in a way that every time the user give the right answer , the response varies within the following :
Possible responses to a correct answer:
Very good!
Excellent!
Nice work!
Keep up the good work!
while if the user give the incorrect answer the response varies within the following :
Possible responses to an incorrect answer:
No. Please try again.
Wrong. Try once more.
Don't give up!
No. Keep trying.
Use random-number generation to choose a number from 1 to 4 that will be used to select one of the four appropriate responses to each correct or incorrect answer. Use a switch statement to issue the responses.
here is the code that need to be modified :
and make sure you add line comments for each new line of code
EXERCISE 6.57 CODE:
-----------------------------
//Name: IhabAtouf
//Date:02/23/2023
// exercise 6.57 on page 281
//program description: create computer-assisted instruction (CAI) program that help students master thier math skills in multiplications,
// multiplication involving two numbers each is a single digit positive, with encouraging message for succedding and another for failing to answer
// using random fucntion (rand) to generate a random number every time
#include<iostream>// to be able to use input output stream
#include<math.h>//h is a header file in the standard library of the C
#include<cstdlib>//Converts a string into a long integer, also carry the library for definition of memory allocation and random processe
#include<ctime>//converts the given time since epoch to a calendar local time and then to a character representation.
using namespace std;//using the standard library
int answer;//global varibale that can be used by any function in this code
void questionGenerator() {//the function that generates the multiplication question
srand(time(NULL));// using the random function that changes every time per second
//here is the initial variable as zero by default
int initial = 0;
// here is two vraibales number1 and number2 that are required to multiply two numbers
int number1;
int number2;
number1 = (initial + (rand()) % 10);//the value of number1 using the follwing math : zero + any random number that has remainder of 10 using the remainder modulus
number2 = (initial + (rand()) % 10);//the value of number2 using the follwing math : zero + any random number that has remainder of 10 using the remainder modulus
answer = number1 * number2;// the asnwer variable that equals the multiplication of those two numbers (number1 and 2)
cout << "How much is " << number1 << " times " << number2 << " ?" << endl;//print how much is number 1 multiplied by number 2 ?
}
int main() {// the main function
int studentResponse = 1;// declaring local variable called student response
questionGenerator();// calling the question generator function
while (studentResponse != -1) {// as long as the student response not equal to -1 then:
cout << "Enter the correct answer" << endl;// print enter the correct answer statement
cin >> studentResponse;// allow user to input the student response variables value
if (answer == studentResponse) {//if the studenrt response entered by user equal the answer variable of multiplying those two numbers1 and number2 variables
cout << "Very Good!" << endl;// then print very good statement
questionGenerator();// then recall the function again for the net set of random numebrs multiplication
continue;// continue till user enter incorrect answer
}
else {// otherwise when answer not correct then print please try again statement
cout << "Please try again!" << endl;
while (studentResponse != answer) {// while loop if student response not equal to the correct answer then:
cout << "Enter the correct answer" << endl;//print message enter correct answer
cin >> studentResponse;//allow user to reneter hoping to get the correct answer, this will keep repeats as long as the student answer and the corredct answer doesnt match
if (answer == studentResponse) {// if the answer match with student answer then:
cout << "Very Good!" << endl;// then print very good statement
questionGenerator();// then recall the function again for the net set of random numebrs multiplication question
continue;// continue till user input incorrect answer
}
}
}
}
return 0;
}
------------------------------
END OF CODE
Here is the approach :
- To generate the random number in c++ is very easy task .
- We have to use the random generator . Hence get the random generator .
- We want to generate the random number within the range of 1 to 4 because we have total 4 messages in both the cases success and failure .
- Hence to generate the random number within the range of 1 to 4 ---> 1+ (rand() % 4)
- Here we are using the modulo operator to generate the random number in the range .
- Next we need the switch case .
- In the switch case switch the randomly generated number .
- In the code store the randomly generated message in some string variable .
- Check the code and output in the second step . Everything is mentioned in the comments .
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 6 images
- Statistics are often calculated with varying amounts of input data. Write a program that takes any number of non-negative integers as input, and outputs the average (using integer division) and max. A negative integer ends the input and is not included in the statistics. Ex: When the input is: 15 20 0 5 -1 the output is: 10 20 Assume that at least one non-negative integer is input.arrow_forwardLets say we are creating a python game. A word is displayed gets displayed on the screen. The players of the game must type as many words as they an that are related to the word that is displayed. If players type in the same word multiple times, it is ignored. One the players are done taking turns, the program gives each player a score that is based off how many wrods they entered that are similiar to what other words players have entered. So for a player to get a point, the word they typed must be typed by another student. QUESTION: We need to store the words typed by the players and all words etered. Would we use a list, set, dict or tuple?arrow_forwardWrite a program that will figure out the required change for a purchase. Start by asking the user for the price of the product and the amount paid. (We are expecting that the user will give a larger value for the amount paid.) Read in each of these values as a double. Report back to the user the number of each denomination of change due. You are not just telling the user the amount of money he gets back. Hint: Working with integers is much easier. The modulo operator is your friend for this assignment. Also, note that pennies can be tricky due to the poor real number to binary conversions. (Remember that 1.00 could actually be stored as 0.9999999999997.) Do not include five-dollar bills, ten-dollar bills, etc. Only show coins and one-dollar bill amounts. Be sure to test multiple values. There is a test case below. Your program should run the test case exactly as it appears below, and should work on any other case in general. Output Example (User input is marked with >>>.…arrow_forward
- Choose a series (Any series you can find in your math notes or on the internet) and program it to find the solution. The starting and ending points should be input by the user in the program. Use good programming guidelines that we talked in class (clear all, comment lines etc...)...arrow_forward# Exercise 4: What is the input() piece in code called? # Why do we use things like print(), input(), or our own sets? # Why do we use comments? # Why do we use variables? # What do we do we do before we take an input? Why? # Please print this answer using only one print statementarrow_forwardWrite a Java program that will use while loops. The while loop will show the cards currently in the hand and ask the user to accept a card (Hit) or to stop (Stand). Within the while loop the program should print the card that was just added, all the cards in the hand, and the new value of the hand. If the value of the hand exceeds 21, the game should end (the while loop should stop). Write out the algorithm for the while loop. Turn in a printout of the algorithm, the code and a printout of a sample run. Place the algorithm and the sample run inside comment blocks in the code. "The sample runs of such a program are on the attached image."arrow_forward
- Answer in Java pleasearrow_forwardExercise 3: Write a program to simulate an experiment rolling two six sided "fair" dice. Allow the user to enter the number of rolls of the dice to simulate. What percentage of the time does the sum of the dots of the dice equal eight in the ● simulation?arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education