J
John
I'm creating this program to test an elementary
school kids math skills. They have five options to
choose from
1 = '+'
2 = '-'
3 = '*'
4 = '/'
0 = To have the computer choose.
My Problem is that when you choose " 0 " the
randomization doesn't work consistently. The computer
does choose the mathematical sign but it looses its
random consistancy, for example; the uwer chooses 0 ( to
let the computer choose the mathematical sign ) and this
is what it would look like:
6 * 6 =
6 * 9 =
9 * 5 =
4 * 7 = etc......
Now, this is what it SHOULD look like:
9 - 4 =
5 * 7 =
4 + 5 =
6 + 8 = ....etc
Sorry if the code is a little messy, I didn't know
how to attach a message, so I copied it straight from the
file.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
int Random_num ( void );
int main()
{
unsigned int counter,
number1, number2,
panswer,
R_answer,
choice,
point;
double final_score;
enum { add = 1, subtract, multiply, division };
cout << " Welcome to the Elementary Math Help. This
program will test your n/"
<< " skills in Addition, Subtraction,
Multiplication, and Division."<< endl;
cout << " Choose 1 for addition \n"
<< " Choose 2 for subtraction \n"
<< " Choose 3 for multiplication \n"
<< " Choose 4 for Division \n "
<< " or press 0 for the computer to choose \n";
cin >> choice;
counter = 0;
point = 0;
srand( time (0) );
if ( choice == 0 )
choice = rand()% 3 + 1;
while ( counter != 5 ){
R_answer = 0;
panswer = 0;
number1 = Random_num();
number2 = Random_num();
switch ( choice ){
case add:
R_answer = number1 + number2;
cout << number1 << " + " << number2 << " = ";
counter++;
cin >> panswer;
break;
case subtract:
R_answer = number1 - number2;
cout << number1 << " - " << number2 << " = ";
counter++;
cin >> panswer;
break;
case multiply:
R_answer = number1 * number2;
cout << number1 << " * " << number2 << " = ";
counter++;
cin >> panswer;
break;
case division:
R_answer = number1 / number2;
cout << number1 << " / " << number2 << " = ";
counter++;
cin >> panswer;
break;
default: cout << " Program Bug. ";
break;
}
if ( panswer == R_answer )
point++;
}
final_score = static_cast <double> ( point ) / 2;
if ( final_score <= .75 )
cout << " You scored low, please try again. " << endl;
cout << "Your score is " << setprecision (2)
<< setiosflags ( ios :: fixed | ios :: showpoint )
<< final_score << endl;
return 0;
}
int Random_num ( void )
{
int num;
num = 1 + rand() % 9;
return num;
}
school kids math skills. They have five options to
choose from
1 = '+'
2 = '-'
3 = '*'
4 = '/'
0 = To have the computer choose.
My Problem is that when you choose " 0 " the
randomization doesn't work consistently. The computer
does choose the mathematical sign but it looses its
random consistancy, for example; the uwer chooses 0 ( to
let the computer choose the mathematical sign ) and this
is what it would look like:
6 * 6 =
6 * 9 =
9 * 5 =
4 * 7 = etc......
Now, this is what it SHOULD look like:
9 - 4 =
5 * 7 =
4 + 5 =
6 + 8 = ....etc
Sorry if the code is a little messy, I didn't know
how to attach a message, so I copied it straight from the
file.
#include <iostream>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;
int Random_num ( void );
int main()
{
unsigned int counter,
number1, number2,
panswer,
R_answer,
choice,
point;
double final_score;
enum { add = 1, subtract, multiply, division };
cout << " Welcome to the Elementary Math Help. This
program will test your n/"
<< " skills in Addition, Subtraction,
Multiplication, and Division."<< endl;
cout << " Choose 1 for addition \n"
<< " Choose 2 for subtraction \n"
<< " Choose 3 for multiplication \n"
<< " Choose 4 for Division \n "
<< " or press 0 for the computer to choose \n";
cin >> choice;
counter = 0;
point = 0;
srand( time (0) );
if ( choice == 0 )
choice = rand()% 3 + 1;
while ( counter != 5 ){
R_answer = 0;
panswer = 0;
number1 = Random_num();
number2 = Random_num();
switch ( choice ){
case add:
R_answer = number1 + number2;
cout << number1 << " + " << number2 << " = ";
counter++;
cin >> panswer;
break;
case subtract:
R_answer = number1 - number2;
cout << number1 << " - " << number2 << " = ";
counter++;
cin >> panswer;
break;
case multiply:
R_answer = number1 * number2;
cout << number1 << " * " << number2 << " = ";
counter++;
cin >> panswer;
break;
case division:
R_answer = number1 / number2;
cout << number1 << " / " << number2 << " = ";
counter++;
cin >> panswer;
break;
default: cout << " Program Bug. ";
break;
}
if ( panswer == R_answer )
point++;
}
final_score = static_cast <double> ( point ) / 2;
if ( final_score <= .75 )
cout << " You scored low, please try again. " << endl;
cout << "Your score is " << setprecision (2)
<< setiosflags ( ios :: fixed | ios :: showpoint )
<< final_score << endl;
return 0;
}
int Random_num ( void )
{
int num;
num = 1 + rand() % 9;
return num;
}