Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MAIN.CPP
- #include <iostream>
- #include <string>
- #include "math.h"
- using namespace std;
- string welcome = "Simple Additon v1.0\n\n";
- string name;
- int getValue()
- {
- int a;
- cout<<"Please enter a number.\n";
- cin>>a;
- cout<<"\n";
- return a;
- }
- string getName()
- {
- string b;
- cout<<"Please enter your name.\n";
- cin>>b;
- cout<<"\n";
- return b;
- }
- string operation()
- {
- string c;
- cout<<"Please enter the operation you want to do. (add, subtract, multiply, or divide.\n";
- cin>>c;
- cout<<"\n";
- return c;
- }
- int main()
- {
- cout<<welcome;
- string name = getName();
- cout<<"Hello "<<name<<"!"<<"\n\n";
- int x = getValue();
- int y = getValue();
- string op = operation();
- if (op == "add")
- {
- cout<<"The answer is: "<<add(x, y);
- }
- if (op == "subtract")
- {
- cout<<"The answer is: "<<subtract(x, y);
- }
- if (op == "multiply")
- {
- cout<<"The answer is: "<<multiply(x, y);
- }
- if (op == "divide")
- {
- cout<<"The answer is: "<<divide(x, y);
- }
- return 0;
- }
- MATH.H
- /* math.h
- Does math related operations with integers
- by Brendan Gowen
- */
- // header guard
- #ifndef MATH_H
- #define MATH_H
- int add(int x, int y)
- {
- return x + y;
- }
- int subtract(int x, int y)
- {
- return x - y;
- }
- int multiply(int x, int y)
- {
- return x * y;
- }
- int divide(int x, int y)
- {
- return x / y;
- }
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement