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
#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;
}
}
Step by stepSolved in 3 steps with 2 images
- Using python, please explain 1: A positive integer greater than 1 is said to be prime if it has no divisors other than 1 and itself. A positive integer greater than 1 is composite if it is not prime. Write a program that asks the user to enter an integer greater than 1, then displays all of the prime numbers that are less than or equal to the number entered The program should work as follows: Once the user has entered a number, the program should populate a list with all of the integers from 2 up through the value entered. The program should then use a loop to step through the list. The loop should pass each element to a function that displays the element whether it is a prime number.arrow_forwardplease solve as soon as possiblearrow_forwardSolve it as soon as possible using C programarrow_forward
- In Java: Forms often allow a user to enter an integer. Write a program that takes in a string representing an integer as input, and outputs yes if every character is a digit 0-9. Ex: If the input is: 1995 the output is: yes Ex: If the input is: 42,000 or 1995! the output is: no Hint: Use a loop and the Character.isDigit() function.arrow_forwardScenario: I am trying to create a recursion function that takes a number from the user. That number then goes through to equations where it squares the number and takes the square root of it. Then, that value is supposed to be sent back through the function, through the same equations. Then, I am trying to output the value of each iteration. The amount of iterations is a random number. This code is in C++ and I am using Visual Studio 2023. I have attached the code I, myself, typed and picture of the output. Also, this is a header file that is being called from my source.cpp file (case 5 in switch case). That is why I am entering 5 as the first input when I run the program. Problem: The output only shows one iteration of calculation, then goes straight back into taking an input from the user. What am I doing wrong?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