嗨我正在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