2016-04-10 4 views
-3

Sadece C kullanarak basit bir hesap oluşturdum Şimdi benim kodumla, sadece bir seferde işlemleri 1 hesaplayabiliyorum. bu nedenle, hesapımı yeniden yapmak veya ti yapısına sahip olmadan başka bir program yapmak için hangi kodu veya döngüyü kullanmalıyım?Çok Temel C işlevi

`

#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, ve işlem) -'> 'scanf ("% c", ve işletme); 've kullanımı' –

cevap

1

Yeniden adlandır int main (void) ' 'int hesap makinesi (boşluk)' için: burada da benim kodudur. yeni bir ana sağlayın:

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

Oh do..while' - ve Sourav tarafından yayınlanan UB cockup düzeltmek :( –

+0

çok güzel teşekkürler kardeşim çok teşekkürler :) –