用C++编程实现下面的问题,高手来帮帮忙,谢谢!在线等
为帮助小学生学习乘法,请应用rand生成两个1位整数,程序利用两个整数输出如下问题:6*7=?,然后由学生来计算答案。程序将检查学生的答案。如果正确,输出“Verygoo...
为帮助小学生学习乘法,请应用rand生成两个1位整数,程序利用两个整数输出如下问题:6*7=?,然后由学生来计算答案。程序将检查学生的答案。如果正确,输出“Very good!",并提问另一个问题。如果回答错误,程序将输出“NO PLEASE TRY AGAIN."让学生重新计算这个问题,直到答案正确为止。
谢了,哥们,小弟刚学C++,不会啊 展开
谢了,哥们,小弟刚学C++,不会啊 展开
3个回答
展开全部
这是我用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");
}
#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");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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++;
}
}
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++;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#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;
}
#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;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询