嗨,我正在使用 while(true) 编写一个简单的计算器,它的工作原理是,当循环结束并再次开始时,它会重复第一行两次,有人有解决方案吗?提前致谢 ...
#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);
}}}}}}
}}