非常基本的C功能

时间:2016-04-10 16:53:51

标签: c

我刚用C创建了一个简单的计算器。 现在通过我的代码,我一次只能计算1个操作。 因此,我应该使用什么代码或循环重做我的计算或做另一个没有ti构建并再次运行我的程序。 这是我的代码:

`

#include <stdio.h>
#include <stdlib.h>

int main(void)
{

   float first_value;
   float second_value;
   char Operation;


   printf("Welcome to Shoeb's first calculator :)\nChoose your operation (a for Addition/s for Subtraction/m for Multiplication/d for Division) \nPress  small o when done calculation ^_^\n");

   scanf("%s", &Operation);


    if (Operation == 'a') {

        printf("Type in your first number below.\n");
        scanf("%f", &first_value);

        printf("Type in you second value below.\n");
        scanf("%f", &second_value);

        printf("The result is %f", first_value+second_value);

    }



    if (Operation == 's') {

        printf("Type in your first number below.\n");
        scanf("%f", &first_value);

        printf("Type in you second value below.\n");
        scanf("%f", &second_value);

        printf("The result is %f", first_value-second_value);

   }

    if (Operation == 'm') {

        printf("Type in your first number below.\n");
        scanf("%f", &first_value);

        printf("Type in you second value below.\n");
        scanf("%f", &second_value);

        printf("The result is %f", first_value*second_value);

   }

    if (Operation == 'd') {

        printf("Type in your first number below.\n");
        scanf("%f", &first_value);

        printf("Type in you second value below.\n");
        scanf("%f", &second_value);

        printf("The result is %f\n", first_value/second_value);

   }
       return 0;
}

`

1 个答案:

答案 0 :(得分:1)

将'int main(void)'重命名为'int calculator(void)'。做一个新的主要:

int main(void){
  while(1) calculator();
};