How to keep count of right answer and wrong answers in C++?

Joined
Nov 2, 2021
Messages
1
Reaction score
0
Currently working on addition program that will loop until the user enters "n".

It will generate two random numbers and display to the user to add them. The user will then input the answer and the program with check if the answer is right or wrong.


My code is working fine however I need help for my code below to keep count of right and wrong answers.


I have not tired anything because I do not know how to do it.


/******************************************************************************
Basic Template for our C++ Programs.
STRING
*******************************************************************************/
#include <stdio.h> /* printf, scanf, puts, NULL */
#include <stdlib.h> /* srand, rand */
#include <time.h> /* time */
#include <string> // String managment funtions.
#include <iostream> // For input and output
#include <cmath> // For math functions.
#include <math.h>
#include <cstdlib>
using namespace std;
////////////////////////////////////////////////////////////////////////



int main()
{
srand(time(0));

string keepgoing;
do
{
const int minValue=10;
const int maxValue=20;

int y = (rand()% (maxValue - minValue +1 )) + minValue;
// cout<< " the random number is y "<< y << endl;
int x = (rand()% (maxValue - minValue +1 )) + minValue;
// cout<< " the random number is x "<< x << endl;


cout<< " what is the sum of "<< x << " + " <<y<<" =" << endl;
int answer;
cin>>answer;

int right=0;
int wrong =0;
wrong++;


if (answer == (x+y)) {
cout << "Great!! You are really smart!!" <<endl;

}

else {
cout << "You need to review your basic concepts of addition" << endl;

}
cout << "Right: "<<right << endl ;
cout << "Wrong: "<< wrong<< endl;

cout<< "Do you want to try agian [enter y (yes) or n (no) ]";
cin >> keepgoing;

}
while( keepgoing == "y");
return 0;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top