算法思想:
(1) 产生两个随机数
(2) 产生一个运算符
(3) 用户输入答案
(4) 验证答案正确与否
(5) 转(1) 重复执行
主函数中用到了srand(time(NULL))上百度查了一下和随机产生有关。如果在程序运行时没有自主设置种子的话,用函数rand产生的随机数序列会是一样的。
而用srand设置随机数种子后,可能产生不同的随机序列(概率很大)。
int main()
{
int number = 2;
int choice;
srand(time(NULL));
do
{
ShowMenu();
choice = getchar();
getchar(); //清除行尾回车
switch(choice)
{
case '1':
case '2':
case '3':
case '4':
case '5':
Arithmetic(choice,number);
break;
case '6':
cout<
cin>>number;
getchar();
}
}
while(choice!='0');
return 0;
}主函数中调用了两个函数:菜单函数ShowMenu和四则运算函数Arithmetic。