用C++编程实现下面的问题,高手来帮帮忙,谢谢!在线等

为帮助小学生学习乘法,请应用rand生成两个1位整数,程序利用两个整数输出如下问题:6*7=?,然后由学生来计算答案。程序将检查学生的答案。如果正确,输出“Very good!",并提问另一个问题。如果回答错误,程序将输出“NO PLEASE TRY AGAIN."让学生重新计算这个问题,直到答案正确为止。
谢了,哥们,小弟刚学C++,不会啊

第1个回答  2009-04-16
这是我用C写的,你改成C++就可以了

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <time.h>
void main ()
{
int m,n,x;
char reply;

srand ((unsigned)time(NULL));
do
{
m=rand()%10;
n=rand()%10;
printf ("please input the answer:\n");
do
{
printf ("%d*",m);
printf ("%d=",n);
scanf ("%d",&x);
if (x==m*n)
{
printf ("You are right!\n");

}
else
printf ("You are wrong!Please try again!\n");
}while (x!=m*n);
printf ("Answer another question? (y/n or Y/N)");
reply=getche();
printf ("\n");
}while(reply=='y'||reply=='Y');
printf ("over\n");
}
第2个回答  2009-04-16
#include<iostream>
using namespace std;
int rand(int x)
{
return(++x);
}
void show(int n,int x,int y)
{
if(n==x*y)
{
cout<<"Very good!"<<endl;
}
else
{
cout<<"No,please try again!"<<endl;
cin>>n;
show(n,x,y);
}

}
void main()
{
int i=2,j=3,n;
bool choice=true;
while(choice==true)
{
cout<<rand(i)<<"*"<<rand(j)<<"=";
cin>>n;
show(n,rand(i),rand(j));
cout<<"answer another qestion?(Y/N)";
char ch;
cin>>ch;
if(ch=='Y'||ch=='y') choice=true;
else if(ch=='N'||ch=='n') choice=false;
i++;j++;
}
}本回答被提问者采纳
第3个回答  2009-04-16
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
srand((unsigned)time(NULL));

int x=rand()%10;
int y=rand()%10;
int result=x*y;

do
{
int n;
cout<<x<<'*'<<y<<'=';
cin>>n;
if(n==result)
{
cout<<"Very good!"<<endl;
break;
}
else cout<<"NO PLEASE TRY AGAIN"<<endl;
}while(1);

return 0;
}
相似回答