Posted By


OdnetninI on 09/08/12

Tagged


Statistics


Viewed 513 times
Favorited by 0 user(s)

Calculator V 1.3


/ Published in: C
Save to your folder(s)

Version 1.3 of a Very Simple Calculator.


Copy this code and paste it in your HTML
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3.  
  4. float a = 0;
  5. float b = 0;
  6.  
  7. void AskNumbers ()
  8. {
  9. printf("Elige el primer Número: ");
  10. scanf("%f", &a);
  11. printf("Elige el segundo Número: ");
  12. scanf("%f", &b);
  13. }
  14.  
  15. int main()
  16. {
  17. uint8_t salir = 0;
  18. uint8_t opcion = 0;
  19.  
  20. while(salir == 0)
  21. {
  22. printf("Basic Calculador by OdnetninI\n");
  23. printf("-----------------------------\n");
  24. printf("1. Suma\n");
  25. printf("2. Resta\n");
  26. printf("3. Multiplicación\n");
  27. printf("4. División\n");
  28. printf("-----------------------------\n");
  29.  
  30. printf("Elija su Opción: ");
  31. scanf("%d", &opcion);
  32.  
  33. if (opcion > 0 && opcion < 5)
  34. AskNumbers();
  35.  
  36. switch (opcion)
  37. {
  38. case 1:
  39. printf("%5.2f + %5.2f = %5.2f\n", a, b, a + b);
  40. break;
  41.  
  42. case 2:
  43. printf("%5.2f - %5.2f = %5.2f\n", a, b, a - b);
  44. break;
  45.  
  46. case 3:
  47. printf("%5.2f * %5.2f = %5.2f\n", a, b, a * b);
  48. break;
  49.  
  50. case 4:
  51. printf("%5.2f / %5.2f = %5.2f\n", a, b, a / b);
  52. break;
  53.  
  54. default:
  55. printf("Operación Desconocida\n");
  56. break;
  57. }
  58.  
  59. printf("¿Desea salir? [0:No, 1:Si]");
  60. scanf("%d", &opcion);
  61. switch (opcion)
  62. {
  63. case 1:
  64. salir = 1;
  65. break;
  66.  
  67. default:
  68. salir = 0;
  69. break;
  70. }
  71. printf("\n");
  72. }
  73.  
  74. return 0;
  75. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.