嗨我正在wrinting一个简单的calulator使用while(true)和它的工作,除了当循环结束并重新开始,它重复第一行两次,有没有人有这个解决方案?在此先感谢...简单的计算器和while循环
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a,ch;
int x,y,i,n,e,s;
while(1) {
printf("\nEnter the operation:");
scanf("%c",&a);
e=a;
if (e=='+') {
printf("\nEnter the first integer:");
scanf("%d",&x);
printf("\nEnter the second integer:");
scanf("%d",&y);
s=x+y;
printf("\nThe result of %d+%d is:%d\n",x,y,s);
} else {
if (e=='-') {
printf("\nEnter the first integer:");
scanf("%d",&x);
printf("\nEnter the second integer:");
scanf("%d",&y);
s=x-y;
printf("\nThe result of %d-%d is:%d\n",x,y,s);
} else {
if (e=='*') {
printf("\nEnter the first integer:");
scanf("%d",&x);
printf("\nEnter the second integer:");
scanf("%d",&y);
s=x*y;
printf("\nThe result of %dx%d is:%d\n",x,y,s);
} else {
if (e=='/') {
printf("\nEnter the first integer:");
scanf("%d",&x);
printf("\nEnter the second integer:");
scanf("%d",&y);
s=x/y;
printf("\nThe result of %d/%d is:%d\n",x,y,s);
} else {
if (e=='%') {
printf("\nEnter the first integer:");
scanf("%d",&x);
printf("\nEnter the second integer:");
scanf("%d",&y);
s=x%y;
printf("\nThe result of %d%%d is:%d\n",x,y,s);
} else {
if (e=='^') {
printf("\nEnter the first integer:");
scanf("%d",&x);
printf("\nEnter the second integer:");
scanf("%d",&y);
s=pow(x,y);
printf("\nThe result of %d^%d is:%d\n",x,y,s);
}}}}}}
}}
我爱你!谢谢 ! – 2013-05-04 19:11:07
哈哈......不客气! – 2013-05-04 19:15:58