小学生减法联系工具,随机生成两个10之内的数字,进行相减,输出答案,如果答案正确,给出提示。
#include<iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void main()
{
int a ,b;
srand(time(0));
a = rand()%10;
b = rand()%10;
if(a<b)
{
int temp = a ;
a = b;
b = temp;
}
cout<<a<<" - "<< b<<" :"<<endl;
int answer;
cin>>answer;
bool correct = (answer == (a - b));
if (correct)
{
cout<<"your answer is right!"<<endl;
}
else
{
cout<<"wrong"<<endl;
}
}