Guest User

Untitled

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