Advertisement
Guest User

dank calculator

a guest
Aug 31st, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. MAIN.CPP
  2.  
  3. #include <iostream>
  4. #include <string>
  5. #include "math.h"
  6.  
  7. using namespace std;
  8.  
  9. string welcome = "Simple Additon v1.0\n\n";
  10. string name;
  11.  
  12. int getValue()
  13. {
  14.     int a;
  15.     cout<<"Please enter a number.\n";
  16.     cin>>a;
  17.     cout<<"\n";
  18.     return a;
  19. }
  20.  
  21. string getName()
  22. {
  23.     string b;
  24.     cout<<"Please enter your name.\n";
  25.     cin>>b;
  26.     cout<<"\n";
  27.     return b;
  28. }
  29.  
  30. string operation()
  31. {
  32.     string c;
  33.     cout<<"Please enter the operation you want to do. (add, subtract, multiply, or divide.\n";
  34.     cin>>c;
  35.     cout<<"\n";
  36.     return c;
  37. }
  38.  
  39. int main()
  40. {
  41.     cout<<welcome;
  42.     string name = getName();
  43.     cout<<"Hello "<<name<<"!"<<"\n\n";
  44.    
  45.     int x = getValue();
  46.     int y = getValue();
  47.     string op = operation();
  48.    
  49.     if (op == "add")
  50.     {
  51.         cout<<"The answer is: "<<add(x, y);
  52.     }
  53.     if (op == "subtract")
  54.     {
  55.         cout<<"The answer is: "<<subtract(x, y);
  56.     }
  57.     if (op == "multiply")
  58.     {
  59.         cout<<"The answer is: "<<multiply(x, y);
  60.     }
  61.     if (op == "divide")
  62.     {
  63.         cout<<"The answer is: "<<divide(x, y);
  64.     }
  65.     return 0;
  66. }
  67.  
  68. MATH.H
  69.  
  70. /* math.h
  71. Does math related operations with integers
  72. by Brendan Gowen
  73. */
  74.  
  75. // header guard
  76. #ifndef MATH_H
  77. #define MATH_H
  78.  
  79. int add(int x, int y)
  80. {
  81.     return x + y;
  82. }
  83.  
  84. int subtract(int x, int y)
  85. {
  86.     return x - y;
  87. }
  88.  
  89. int multiply(int x, int y)
  90. {
  91.     return x * y;
  92. }
  93.  
  94. int divide(int x, int y)
  95. {
  96.     return x / y;
  97. }
  98.  
  99. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement