Advertisement
Guest User

SimpleCalc V.3

a guest
May 20th, 2013
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. // SimpleCalc.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <windows.h>
  6. #include <iostream>
  7. #include <cstdlib>
  8. using namespace std;
  9.  
  10. //Variables
  11. int fnum;
  12. int snum;
  13. int result;
  14. char sym;
  15. char st();
  16. char loop = 'y';
  17. char ff();
  18. int calc();
  19. int wait;
  20.  
  21. //Main stuff
  22.  
  23. int main(int nNumberofArgs, char*
  24. pszArgs[])
  25.  
  26. {
  27. SetConsoleTitle( TEXT( "SimpleCalc" ) );
  28.  
  29. cout << ("Welcome to SimpleCalc!") <<endl;
  30. cout << ("Project By: Christopher Altig!") <<endl;
  31.  
  32.  
  33. while (loop == 'y')
  34. {
  35. ff();
  36. if (sym == '*')
  37. {
  38. result = fnum * snum;
  39. cout << "Answer:" << result <<endl;
  40. st();
  41. }
  42. else if (sym == '/')
  43. {
  44. result = fnum / snum;
  45. cout << "Answer:" << result <<endl;
  46. st();
  47. }
  48. else if (sym == '-')
  49. {
  50. result = fnum - snum;
  51. cout << "Answer:" << result <<endl;
  52. st();
  53. }
  54. else if (sym == '+')
  55. {
  56. result = fnum + snum;
  57. cout << "Answer:" << result <<endl;
  58. st();
  59. }
  60. else if (sym == '%')
  61. {
  62. result = snum % fnum;
  63. cout << "Answer:" << result <<endl;
  64. st();
  65. }
  66. }
  67. return 0;
  68. }
  69. //Down here V V V
  70. char st()
  71. {
  72. cout << ("Do another calculation (Y/N): ");
  73. cin >> loop;
  74. if (loop == 'n')
  75. {
  76. exit (EXIT_SUCCESS);
  77. }
  78. else if (loop !='n' && loop !='y')
  79. {
  80. cout << ("Error: Invalid Character!") <<endl;
  81. st();
  82. }
  83.  
  84. return 0;
  85. }
  86.  
  87. char ff()
  88. {
  89. cout << "Symbol here:"; cin >> sym;
  90. if (sym == '*' || sym == '/' || sym == '+' || sym == '-' || sym == '%')
  91. {
  92. calc();
  93. }
  94. else
  95. {
  96. cout << ("Error: Invalid Character!") <<endl;
  97. ff();
  98. }
  99.  
  100. return 0;
  101. }
  102.  
  103. int calc()
  104. {
  105. snum = 0;
  106. fnum = 0;
  107. system("CLS");
  108. cout << "Number 1:"; cin >> fnum;
  109. cout << "Number 2:"; cin >> snum;
  110. if (snum >= 0 || fnum >= 0)
  111. {
  112. cout << ("Error: Invalid Number!") << endl;
  113. wait = 0;
  114. while (wait <= 5)
  115. {
  116. wait++;
  117. }
  118. system("CLS");
  119. calc();
  120. }
  121. else
  122. {
  123. ff();
  124. }
  125. return 0;
  126. }
  127. //Up there ^ ^ ^
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement