Advertisement
bobbinz

Rubbish Calculator

Nov 7th, 2018
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.97 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main()
  5. {
  6.     int func,num1,num2;
  7.     float result;
  8.     printf("Welcome to the world's most rubbish calculator\n\n");
  9.     printf("What function do you require?\n");
  10.     printf("Press 1 for addition\n");
  11.     printf("Press 2 for subtraction\n");
  12.     printf("Press 3 for multiplication\n");
  13.     printf("Press 4 for division\n");
  14.     scanf("%d",&func);
  15.     printf("\nEnter your first value\n");
  16.     scanf("%d",&num1);
  17.     printf("\nEnter your second value\n");
  18.     scanf("%d",&num2);
  19.     switch(func)
  20.     {
  21.         case 1:result = num1 + num2;
  22.             break;
  23.         case 2:result = num1 - num2;
  24.             break;
  25.         case 3:result = num1 * num2;
  26.             break;
  27.         case 4:result = (float)num1 / (float)num2;
  28.             break;
  29.         default: printf("\nERROR! I have no idea what you are on about mate!\n");
  30.             return 1;
  31.     }
  32.     printf("\nYour answer is... %g\n",result);
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement