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

2024-12-19 05:27:00
推荐回答(3个)
回答1:

这是我用C写的,你改成C++就可以了

#include
#include
#include
#include
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:

#include
using namespace std;
int rand(int x)
{
return(++x);
}
void show(int n,int x,int y)
{
if(n==x*y)
{
cout<<"Very good!"< }
else
{
cout<<"No,please try again!"< cin>>n;
show(n,x,y);
}

}
void main()
{
int i=2,j=3,n;
bool choice=true;
while(choice==true)
{
cout< 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:

#include
#include
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< cin>>n;
if(n==result)
{
cout<<"Very good!"< break;
}
else cout<<"NO PLEASE TRY AGAIN"< }while(1);

return 0;
}