Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please help me with this code , i want to use userconfirmation to control the pr

ID: 3613135 • Letter: P

Question

please help me with this code , i want to use userconfirmation to control the program forexample if i enter Y the program will continue to ask question andif i enter anything else the program will quit.this my codebelow.


#include <iostream>
#include <cmath> //for srand and rand function
#include <ctime> //for time function

using namespace std;

int main()
{
    int correctcount = 0; //count the number ofcorrect answers
    long startTime = time(0);
  
cout << "Enter y to continue and N to quit thequestion ::";
char continuecount = 'Y';
cin >> continuecount;




while(continuecount == 'Y')
{
                     


//1.Generate two random numbers
srand(time(0));
int number1 = rand() % 10;
int number2 = rand() % 10;


//2.if number1 < number2 , swap number1 with number2
if(number1 < number2)
{
int temp = number1;
number1 = number2;
number2 = temp;
}


//3.prompt the student to answer "what is number1 -number2"
cout << "What is " << number1 <<" - "<< number2 << " ? ";
int answer;
cin >> answer;


//4.Grade the answer and display the result
if(number1 - number2 == answer)
{
cout <<" you are correct! ";
correctcount++;
}

else

cout <<"Your answer is wrong !!" << number1<<" - " << number2
      <<"should be "<<(number1 - number2) <<" ";

//Enter capital y to continue or n to quit:
cout << "Enter y to continue and N to quit thequestion ::";
char continuecount;
cin >> continuecount;

}




long endTime = time(0);
long testTime = endTime - startTime;

cout <<"correct count is " << correctcount<<" ";
cout <<"The test time is " << testTime<<" ";

system("pause");
return 0;
}

Please i will rate to the maximum

Explanation / Answer

please rate - thanks I see 3 problems 1) don't ask if they want to continue at the beginning of theprogram. you were probably thinking you had to initialize the loopbut    char continuecount ='Y';      does that 2) check for 'Y' and 'y' especially since your prompt has a yin it not a Y 3) you are redefining char continuecount;  just before you read it in giving you a scope problem. of the2nd one hope the answer wasn't too detailed but a good hint