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;
}
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;
}