fork download
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. using namespace std;
  6.  
  7. char textMessage[512];
  8. char stringResult[256];
  9. char stringFirst[32];
  10. char stringSecond[32];
  11. char symbolOperation[] = "";
  12. double operandFirst = 0, operandSecond = 0, operandResult = 0;
  13. int identifierOperation = 0;
  14. bool existenceFirstOperand = false, existenceSecondOperand = false, existenceResultOperand = false;
  15.  
  16. void onClickNumber(int num);
  17. void onClickOperation(int id);
  18. void onClickResult(void);
  19. void Cleaning(void);
  20.  
  21. int main(int argc, char* argv[])
  22. {
  23. onClickNumber(5);
  24. onClickOperation(13);
  25. onClickNumber(10);
  26. onClickResult();
  27.  
  28. printf("%s%s%s = %s\n", stringFirst, symbolOperation, stringSecond, stringResult);
  29.  
  30.  
  31.  
  32. printf("\n");
  33. system("pause");
  34. return EXIT_SUCCESS;
  35. }
  36.  
  37. void onClickNumber(int num)
  38. {
  39. char str[32];
  40. sprintf(str, "%d", num);
  41.  
  42. if (existenceResultOperand)
  43. {
  44. Cleaning();
  45. onClickNumber(num);
  46. return;
  47. }
  48.  
  49. if (identifierOperation == 0)
  50. {
  51. if (operandFirst == 0) strcpy(stringFirst, str);
  52. else strcat(stringFirst, str);
  53. existenceFirstOperand = true;
  54. operandFirst = atof(str);
  55. }
  56. else
  57. {
  58. if (operandSecond == 0) strcpy(stringSecond, str);
  59. else strcat(stringSecond, str);
  60. existenceSecondOperand = true;
  61. operandSecond = atof(str);
  62. }
  63.  
  64. existenceResultOperand = false;
  65.  
  66. strcpy(textMessage, stringFirst);
  67. strcat(textMessage, symbolOperation);
  68. strcat(textMessage, stringSecond);
  69. }
  70.  
  71. void onClickOperation(int id)
  72. {
  73. if (existenceFirstOperand)
  74. {
  75. identifierOperation = id;
  76. switch (id)
  77. {
  78. case 10: strcpy(symbolOperation, "/"); break;
  79. case 11: strcpy(symbolOperation, "*"); break;
  80. case 12: strcpy(symbolOperation, "-"); break;
  81. case 13: strcpy(symbolOperation, "+"); break;
  82. }
  83. }
  84.  
  85. if (existenceResultOperand)
  86. {
  87. strcpy(stringFirst, stringResult);
  88. operandSecond = 0; strcpy(stringSecond, ""); existenceSecondOperand = false;
  89. }
  90.  
  91. operandResult = 0; strcpy(stringSecond, ""); existenceResultOperand = false;
  92.  
  93. strcpy(textMessage, stringFirst);
  94. strcat(textMessage, symbolOperation);
  95. strcat(textMessage, stringSecond);
  96. }
  97.  
  98. void onClickResult(void)
  99. {
  100. if (existenceFirstOperand && existenceSecondOperand)
  101. {
  102. switch (identifierOperation)
  103. {
  104. case 10: operandResult = operandFirst /= operandSecond; break;
  105. case 11: operandResult = operandFirst *= operandSecond; break;
  106. case 12: operandResult = operandFirst -= operandSecond; break;
  107. case 13: operandResult = operandFirst += operandSecond; break;
  108. }
  109.  
  110. if ((int)operandResult == operandResult)
  111. sprintf(stringResult, "%d", (int)operandResult);
  112. else
  113. sprintf(stringResult, "%f", operandResult);
  114.  
  115. existenceResultOperand = true;
  116. }
  117. }
  118.  
  119. void Cleaning(void)
  120. {
  121. strcpy(textMessage, "");
  122. strcpy(stringResult, "");
  123. strcpy(stringFirst, "");
  124. strcpy(stringSecond, "");
  125. strcpy(symbolOperation, "");
  126.  
  127. operandFirst = operandSecond = operandResult = 0;
  128. identifierOperation = 0;
  129. existenceFirstOperand = existenceSecondOperand = existenceResultOperand = false;
  130. }
Success #stdin #stdout #stderr 0s 3456KB
stdin
Standard input is empty
stdout
5+10 = 15

stderr
sh: 1: pause: not found