Guest User

Untitled

a guest
Jan 23rd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5.  
  6. {
  7. int num1;
  8. int num2;
  9. int result;
  10. int answer;
  11. char string1[4] = "sum";
  12. char string2[4] = "sub";
  13. char string3[5] = "mult";
  14. char string4[4] = "div";
  15. char operation[5];
  16.  
  17.  while (loop == 1) {  
  18.  
  19.    printf( "Please enter a number you wish to be calculated: " );
  20.    scanf( "%d", &num1 );
  21.    
  22.    printf ("Please enter another number for the calculation: " );
  23.    scanf( "%d", &num2 );
  24.    
  25.    printf( "Enter either sum, sub, mult or div to see a result: ");
  26.    scanf( "%s", operation );
  27.    
  28.    if (strcmp(operation, string1) == 0)
  29.    {
  30.    result = num1 + num2;
  31.    printf( "The sum of your numbers is: %d \n", result);
  32.    }
  33.    
  34.    else if (strcmp(operation, string2) == 0)
  35.    {
  36.    result = num1 - num2;
  37.    printf("The subtraction of your numbers is: %d \n", result);
  38.    }
  39.    
  40.    else if (strcmp(operation, string3) == 0)
  41.    {
  42.    result = num1 * num2;
  43.    printf("The multiplication of your numbers is: %d \n", result);
  44.    }
  45.    
  46.    else if (strcmp(operation, string4) == 0)
  47.    {
  48.    result = num1 / num2;
  49.    printf("The division of your numbers is: %d \n", result);
  50.    }
  51.    
  52.    else
  53.    {
  54.    printf("You didnt enter a correct keyword! \n");
  55.    }
  56.    
  57.  printf("Would you like to calculate another number? Please enter 1-yes or 0-no: \n");
  58.  scanf( "%d", &answer );
  59.  if (answer = 1, loop = 1);
  60.  if (answer = 0, loop = 0);
  61.  }
  62.    getchar();
  63.    return 0;
  64. }
Add Comment
Please, Sign In to add comment