in C++ here is my code that will ask to answer the multiplication fo teo random numbers when the user enter the right answer, it says very good then it keeps asking the next random set of numbers multiplication answer, till the user answer incorrectly, it says please try again then it exists, i want the program not to exit but to say please try again till the user puts the right answer then it says very good and does to the next question ...etc... can you implemnt what i just asked ? and thank you    code: #include// to be able to use input output stream #include//h is a header file in the standard library of the C programming language designed for basic mathematical operations #include//Converts a string into a long integer, also carry the library for definition of memory allocation and random processe #include//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 unout incorrect answer or -1         }         else {// otherwise when answer not correct then print please try again statement              cout << "Please try again!" << endl;                      }         return 0;     } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in C++

here is my code that will ask to answer the multiplication fo teo random numbers

when the user enter the right answer, it says very good then it keeps asking the next random set of numbers multiplication answer, till the user answer incorrectly, it says please try again then it exists,

i want the program not to exit but to say please try again till the user puts the right answer then it says very good and does to the next question ...etc...

can you implemnt what i just asked ? and thank you 

 

code:

#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 programming language designed for basic mathematical operations
#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 unout incorrect answer or -1


        }
        else {// otherwise when answer not correct then print please try again statement 
            cout << "Please try again!" << endl;
            
        }
        return 0;


    }
}

Microsoft Visual Studio Debux
How much is 3 times 9 ?
Enter the correct answer
27
Very Good!
How much is 6 times 5 ?
Enter the correct answer
30
Very Good!
How much is 6 times 2 ?
Enter the correct answer
12
Very Good!
How much is 3 times 1 ?
Enter the correct answer
3
Very Good!
How much is 9 times 8 ?
Enter the correct answer
2
Please try again!
+
C:\Users\ihaba\source\repos\ConsoleApplication41\x64\Debug\ConsoleApplication41.exe (process 4784) exited with code 0.
Press any key to close this window . . .|
x
Transcribed Image Text:Microsoft Visual Studio Debux How much is 3 times 9 ? Enter the correct answer 27 Very Good! How much is 6 times 5 ? Enter the correct answer 30 Very Good! How much is 6 times 2 ? Enter the correct answer 12 Very Good! How much is 3 times 1 ? Enter the correct answer 3 Very Good! How much is 9 times 8 ? Enter the correct answer 2 Please try again! + C:\Users\ihaba\source\repos\ConsoleApplication41\x64\Debug\ConsoleApplication41.exe (process 4784) exited with code 0. Press any key to close this window . . .| x
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education