// ConsoleApplication3.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include "iostream"
#include "ctime"
using namespace std;
int a, b;
void randAnswer();
int main()
{
int answer;
while (1)
{
randAnswer();
cin >> answer;
if (answer == a*b)
{
cout << "你的回答正确!!!\n";
}
else
{
cout << "你的回答错误\n";
cout << "请重新输入:\n";
cin >> answer;
while (1)
{
if (answer == a*b)
{
cout << "你的回答正确!!!\n";
break;
}
else
{
cout << "你的回答错误\n";
cout << "请重新输入:\n";
cin >> answer;
}
}
}
}
system("pause");
return 0;
}
void randAnswer()
{
srand(time(NULL));//初始化随机函数种子
a = rand() % 10 + 1;
b = rand() % 10 + 1;
cout << a << " * " << b << " = ? " << endl;
}