calculating responses

2 questions

1.I'm trying to calculate the number of correct/incorrect responses after x number of questions, a running total. i.e. 2 correct 1 incorrect.

2. How to exit the loop before the x number of tries are cycled through.

I'm relatively new to programming and like to work through as much as I can from research etc. Can someone give me a hint on how to do these? Thanks


//random multiplication practice 0-10. Want to keep track of correct/incorrect responses.
#include <iostream>
#include <math.h>
#include <time.h>
#include <cstdlib>
using namespace std;
const int LOW =1;
const int HIGH=10;

int main()
{

int num1;
int num2;
int ans;
int count=0;
int correct;
int incorrect;

srand(time(0));//seed-start of rand. number

cout<< "Welcome to Mike's Multiplication Mania"<<endl;
cout<<""<<endl;
num1 =rand() % (HIGH -LOW + 1)+1 ;//rand. num.relates to high/low1-10
num2 =rand() % (HIGH - LOW + 1)+1 ;

cout<< "Your first two numbers to multiply are" " "<<num1<<" ""times" " "<<num2<<endl;
cout<<""<<endl;
cout<<"Please enter your answer"<<endl;
cout<<""<<endl;
cin>>ans;
do{
if (ans==num1*num2)
{
cout<< "That is correct, good job, Try again!"<<endl;//want to start running total of correct/incorrect for user to see.
num1 =rand() % (HIGH -LOW + 1) ;
num2 =rand() % (HIGH - LOW + 1) ;
cout<< num1<<" " "times" " "<< num2 <<endl;
cin>>ans;
}
else
{
cout<<"That is not correct!"<<endl;
cout<<"The correct answer is"" "<<num1*num2<<endl;
cout<<"Try again!"<<endl;
num1 =rand() % (HIGH -LOW + 1) ;
num2 =rand() % (HIGH - LOW + 1) ;
cout<< num1<<" " "times" " "<< num2<<endl;
cin>>ans;
}
} while (count++<3);

system("pause");
return 0;
}

1
2
3
4
5
cout<< "Your first two numbers to multiply are" " "<<num1<<" ""times" " "<<num2<<endl;
cout<<""<<endl;
cout<<"Please enter your answer"<<endl;
cout<<""<<endl; // that line isnt needed
cin>>ans;


1
2
3
4
5
6
7
8
9
10
do{
if (ans==num1*num2)
{
cout<< "That is correct, good job, Try again!"<<endl;//want to start running total of correct/incorrect for user to see. 
num1 =rand() % (HIGH -LOW + 1) ;
num2 =rand() % (HIGH - LOW + 1) ;
cout<< num1<<" " "times" " "<< num2 <<endl;
cin>>ans;
//you need a while statement her i think because you have a do statement above
}


have to go right now so cant look at it anymore sorry

hope that helps

thanks

arcadiu
Have two integer variables for correct and incorrect and increment them accordingly.
Thanks, that has helped me solve quest. #1 I am now able to keep track of a running total of correct and incorrect responses.
Topic archived. No new replies allowed.