由计算机生成简单的四则运算
#include <stdio.h>#include <string.h>
#include <stdlib.h>
void plus(int key,int m,int n)
{
if((m+n)==key)
printf("you've done a great job");
else printf("you are wrong");
}
void minus(int key,int m,int n)
{
if((m-n)==key) printf("you've done a great job");
else printf("you are wrong");
}
void mutiply(int key,int m,int n)
{
if((m*n)==key) printf("you've done a great job");
else printf("you are wrong");
}
void division(float result ,int m,int n)
{
if((m/n)==result)
printf("you've done a great job");
else printf("you are wrong");
}
void operate()
{
char ch,a[10];
int key;
printf("please choose the style of computation:");
scanf("%c",&ch);
if((ch=getchar())=='+')
{
int m,n;
printf("tens digit or one digit?");
gets(a);
if(strcmp(a,"tens digit")==0)
{
m=rand()%100;n=rand()%100;
printf("%d+%d=",m,n);
scanf("%d",&key);
plus(key,m,n);
}
else if(strcmp(a,"one digit")==0)
{
m=rand()%10;n=rand()%10;
printf("%d+%d=",m,n);
scanf("%d",&key);
plus(key,m,n);
}
}
if((ch=getchar())=='-')
{
int m,n;
printf("tens digit or one digit?");
gets(a);
if(strcmp(a,"tens digit")==0)
{
m=rand()%100;n=rand()%100;
printf("%d-%d=",m,n);
scanf("%d",&key);
minus(key,m,n);
}
else if(strcmp(a,"one digit")==0)
{
m=rand()%10;n=rand()%10;
printf("%d-%d=",m,n);
scanf("%d",&key);
minus(key,m,n);
}
}
if((ch=getchar())=='*')
{
int m,n;
printf("tens digit or one digit?");
gets(a);
if(strcmp(a,"tens digit")==0)
{
m=rand()%100;n=rand()%100;
printf("%d*%d=",m,n);
scanf("%d",&key);
mutiply(key,m,n);
}
else if(strcmp(a,"one digit")==0)
{
m=rand()%10;n=rand()%10;
printf("%d*%d=",m,n);
scanf("%d",&key);
mutiply(key,m,n);
}
}
if((ch=getchar())=='/')
{
int m,n;
float result;
printf("tens digit or one digit?");
gets(a);
if(strcmp(a,"tens digit")==0)
{
m=rand()%100;n=rand()%100;
printf("%d/%d=",m,n);
scanf("%f",&result);
division(result,m,n);
}
else if(strcmp(a,"one digit")==0)
{
m=rand()%10;n=rand()%10;
printf("%d/%d=",m,n);
scanf("%f",&result);
division(result,m,n);
}
}
}
void main()
{
char t;
do
{
printf("Do you want to start?");
if((t=getchar())=='Y') operate();
}while((t=getchar())=='N');
}
题目是由计算机生成简单的四则运算题;用户给出答案;计算机判断对错。直到用户回答说不再继续做了时结束程序
个位帮我看看到底哪出错了,拜求!!!!