码迷,mamicode.com
首页 > 其他好文 > 详细

四则运算

时间:2016-03-17 00:18:52      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

首先要感谢各位同学的,尤其是吴阿平同学的帮助和耐心讲解。

感觉到自己编写代码的能力实在是有待加强,需要长时间的积累和磨练。

#include<stdio.h>
#include<math.h>
#include<windows.h>
int right=0;
int wrong=0;
void add()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d + %d = ",a,b);
scanf("%d",&c);
if(a+b==c)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void minu()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d - %d = ",a,b);
scanf("%d",&c);
if(a-b==c)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void mul()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d * %d = ",a,b);
scanf("%d",&c);
if(a*b==c)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void di()
{
int a,b,c;
a=rand()%100;
b=rand()%100;
printf("请回答:\n\t\t %d / %d = ",a,b);
scanf("%d",&c);
if(a/b==c)
{
printf("回答正确!\n");
right++;
}
else
{
printf("回答错误!\n");
wrong++;
}
}
void main()
{
int choise;
int con=0;
printf("\n\t\t\t欢迎\n\n");
while(1)
{
printf("请选择:\n");
printf("\t\t\t 加法运算(请输入1)\n");
printf("\t\t\t 减法运算(请输入2)\n");
printf("\t\t\t 乘法运算(请输入3)\n");
printf("\t\t\t 除法运算(请输入4)\n");
printf("\t\t\t 退出运算(请输入5)\n");
if(con==0)
scanf("%d",&choise);
switch(choise)
{
case 1:
add();
break;
case 2:
minu();
break;
case 3:
mul();
break;
case 4:
di();
break;
case 5:
return;
}
printf("\n\t\t\t继续运算?(请输入1)\n");
printf("\n\t\t\t重新选择?(请输入2)\n");
printf("\n\t\t\t退出运算?(请输入3)\n");
scanf("%d",&con);
if(con==1)
con=1;
else if(con==2)
con=0;
else if(con==3)
break;
else
printf("出错!请重新输入!\n");
}

技术分享

四则运算

标签:

原文地址:http://www.cnblogs.com/hushihui666/p/5285568.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!