fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. // my first calculator
  5. // gonna make more
  6.  
  7. int main()
  8. {
  9. char op;
  10. int num1 = 0;
  11. int num2 = 0;
  12. int result = 0;
  13. char currency[50] = "$";
  14.  
  15. printf("Enter a number:\n");
  16. scanf("%d", &num1);
  17.  
  18. printf("Enter a number:\n");
  19. scanf("%d", &num2);
  20.  
  21. printf("enter an operator (+,*,/,-):\n");
  22. scanf(" %c", &op);
  23.  
  24. if (op == '+')
  25. {
  26. result = num1 + num2;
  27. }
  28. if (op == '-')
  29. {
  30. result = num1 - num2;
  31. }
  32. else if (op == '/')
  33. {
  34. if (num2 == 0)
  35. {
  36. printf("Error cannot divide by 0\n");
  37.  
  38. return 1;
  39. }
  40.  
  41. result = num1 / num2;
  42. }
  43. if (op == '*')
  44. {
  45. result = num1 * num2;
  46. }
  47.  
  48. printf("Result:%s%d\n", currency,result);
  49.  
  50. system("pause");
  51.  
  52. return 0;
  53. }
  54.  
Success #stdin #stdout #stderr 0.01s 5320KB
stdin
Standard input is empty
stdout
Enter a number:
Enter a number:
enter an operator (+,*,/,-):
Result:$0
stderr
sh: 1: pause: not found