lashunda
09-19-2003, 12:41 AM
Help. I keep getting a fata error everytine I try to run this program. the objective is to create a multiplication program that generates random multiplication problems and offer switch responses.
#include <iostream>
#include <cstdlib>
#include <time.h>
using std::cout;
using std::cin;
using std::endl;
int response;
int num1,
num2,
multiplied,
answer,
status;
void askQuestion(int a, int b)
{
int answer2;
do
{
cout << "\nPlease try again...\n" << endl;
cout << "How much is " << a << "* " << b << "? ";
cin >> answer2;
cout << "\n";
while (answer2 != (a * b))
num1 = 1 + rand() % 10;
num2 = 1 + rand() % 10;
multiplied = num1 * num2;
cout << "How much is " << num1 << "* " << num2 << "? ";
cin >> answer;
srand( time( 0 ) );
if (answer == (num1 * num2))
cout << "Very Good!\n" << endl;
else // else re-ask the question until they get it right.
askQuestion(num1, num2);
switch (response) {
case 1:
printf ("Very good!\n");
break;
case 2:
printf ("Excellent!\n");
break;
case 3:
printf ("Nice work!\n");
break;
case 4:
printf ("Keep up the good work!");
break;
default:
switch (response)
case 5:
printf ("No. Please try again.\n");
break;
case 6:
printf ("Wrong. Try once more.\n");
break;
case 7:
printf ("Don't give up!\n");
break;
case 8:
printf ("No. Keep trying.");
break;
cout << "\nEnter -1 to quit and anything else to continue: ";
cin >> status;
while (status != -1);printf("Enter new problem");
}
#include <iostream>
#include <cstdlib>
#include <time.h>
using std::cout;
using std::cin;
using std::endl;
int response;
int num1,
num2,
multiplied,
answer,
status;
void askQuestion(int a, int b)
{
int answer2;
do
{
cout << "\nPlease try again...\n" << endl;
cout << "How much is " << a << "* " << b << "? ";
cin >> answer2;
cout << "\n";
while (answer2 != (a * b))
num1 = 1 + rand() % 10;
num2 = 1 + rand() % 10;
multiplied = num1 * num2;
cout << "How much is " << num1 << "* " << num2 << "? ";
cin >> answer;
srand( time( 0 ) );
if (answer == (num1 * num2))
cout << "Very Good!\n" << endl;
else // else re-ask the question until they get it right.
askQuestion(num1, num2);
switch (response) {
case 1:
printf ("Very good!\n");
break;
case 2:
printf ("Excellent!\n");
break;
case 3:
printf ("Nice work!\n");
break;
case 4:
printf ("Keep up the good work!");
break;
default:
switch (response)
case 5:
printf ("No. Please try again.\n");
break;
case 6:
printf ("Wrong. Try once more.\n");
break;
case 7:
printf ("Don't give up!\n");
break;
case 8:
printf ("No. Keep trying.");
break;
cout << "\nEnter -1 to quit and anything else to continue: ";
cin >> status;
while (status != -1);printf("Enter new problem");
}