2016-04-10 32 views
-3

私はちょうどCを使用して簡単な電卓を作成しました。 今私のコードでは、私は操作を1つずつ計算することができます。 したがって、私の計算をやり直すのにどんなコードやループを使うべきですか、あるいは私のプログラムをビルドして再度実行することなく別のコードやループを実行する必要があります。非常に基本的なC関数

`

#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

'のscanf( "%sの"、&オペレーション)'と 'do..while' –

答えて

1

名前の変更 'int型メイン(無効)' 'int型の計算(無効)' へ: はよくここに私のコードです。新しいメインください:; - > `のscanf( "%cの"、&オペレーション)`;

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

ああを使用する - とSouravによって投稿されたUBのコックアップを修正してください:( –

+0

はうまくいった仲間のおかげで多くの:) –

関連する問題