Posted By

Desoxena on 12/21/10


Tagged


Versions (?)

calculator


 / Published in: C++
 

you enter in two digits, and it gives you the addition, multiplication, division, and subtraction answer. this calculator also has a useless 'for' loop example that i made while bored.

  1. #include <cstdlib>
  2. #include <iostream>
  3. #include <string>
  4. #include <stdio.h>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. string thing;
  11. cout << "\nwhat do you wanna do?\n" << endl;
  12. cin >> thing;
  13. if (thing == "for")
  14. {
  15. system ("cls");
  16. int x;
  17. for(x=1;x<10;x++)
  18. cout << x << ". hello world!" << endl;
  19. system ("pause");
  20. return 0;
  21. }
  22. else if (thing == "calc")
  23. {
  24. system ("cls");
  25. float x, y;
  26. cout << "\nplease input a number.\n" << endl;
  27. cin >> x;
  28. cout << "\nplease input another number.\n" << endl;
  29. cin >> y;
  30. cout << "\n\n" << x << " + " << y << " equals " << x+y << endl;
  31. cout << "------------addition-------------------------" << endl;
  32. cout << "\n\n" << x << " * " << y << " equals " << x*y << endl;
  33. cout << "------------multiplication-------------------" << endl;
  34. cout << "\n\n" << x << " - " << y << " equals " << x-y << endl;
  35. cout << "------------subtraction---------------------" << endl;
  36. cout << "\n\n" << x << " / " << y << " equals " << x/y << endl;
  37. cout << "------------division------------------------" << endl;
  38.  
  39. system ("pause");
  40. return 0;
  41. }
  42. }

Report this snippet  

You need to login to post a comment.