2008
04-17

我是个刚学C的菜鸟,碰到了问题,向高手请教,谢谢!!!


刚刚早上编了个进行+-*/运算的程序,可是该怎么弄才能让我随便输入什么两个数也能进行计算呢?因为水平有限我只弄了整型的


 


#include <stdio.h>
#include <stdlib.h>
/*use switch statement to finishi it*/


 


int x,y;
int main(void)
{


 


      while(1)
      {
        puts(“please enter two values:”);
        scanf(“%d%d”,&x,&y);
        puts(“please enter the operation you want,such as(+,-,*,/):”);
        getchar();
          switch(getchar())
          {
             case ‘+’:
             {


               printf(“\nafter ‘+’ operation,the result is %d”,x+y);


               break;
             }
             case ‘-’:
             {
                printf(“\nafter ‘-’ operation,the result is %d”,x-y);


               break;
             }
             case ‘*’:
             {
               printf(“\nafter ‘*’ operation,the result is %d”,x*y);


               break;
             }
             case ‘/’:
             {
               
               printf(“\nafter ‘/’ operation,the result is %d”,x/y);


               break;
             }
             default:
             {
               puts(“\nInvalid operation,try again please!”);
             }
             system(“PAUSE”);
             return 0;
          }
      }
 }


 


留下一个回复