Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- int main()
- {
- int num1;
- int num2;
- int result;
- int answer;
- char string1[4] = "sum";
- char string2[4] = "sub";
- char string3[5] = "mult";
- char string4[4] = "div";
- char operation[5];
- while (loop == 1) {
- printf( "Please enter a number you wish to be calculated: " );
- scanf( "%d", &num1 );
- printf ("Please enter another number for the calculation: " );
- scanf( "%d", &num2 );
- printf( "Enter either sum, sub, mult or div to see a result: ");
- scanf( "%s", operation );
- if (strcmp(operation, string1) == 0)
- {
- result = num1 + num2;
- printf( "The sum of your numbers is: %d \n", result);
- }
- else if (strcmp(operation, string2) == 0)
- {
- result = num1 - num2;
- printf("The subtraction of your numbers is: %d \n", result);
- }
- else if (strcmp(operation, string3) == 0)
- {
- result = num1 * num2;
- printf("The multiplication of your numbers is: %d \n", result);
- }
- else if (strcmp(operation, string4) == 0)
- {
- result = num1 / num2;
- printf("The division of your numbers is: %d \n", result);
- }
- else
- {
- printf("You didnt enter a correct keyword! \n");
- }
- printf("Would you like to calculate another number? Please enter 1-yes or 0-no: \n");
- scanf( "%d", &answer );
- if (answer = 1, loop = 1);
- if (answer = 0, loop = 0);
- }
- getchar();
- return 0;
- }
Add Comment
Please, Sign In to add comment