Remember WSQ03, Fun With Numbers?

Well, this weekly task is about using functions in a program that calculates basic mathematical operations of two numbers, such as

  • Addition.
  • Subtraction.
  • Multiplication.
  • Division and its remainder.

I created 4 different functions using “Double” so the results of the operation could be in decimal numbers.

The process of this task was to create the mathematical functions one by one and then call them in the execution code. Like this:

#include <iostream>
#include <math.h>
using namespace std;

double addition (double a, double b){
return a+b;

}

double sustraction (double a, double b){
return a-b;

}

double product (double a, double b){
return a*b;

}

double division (double a, double b){
return a/b;

}

int remainder (int a, int b){
return a%b;

}

int main(){
  double a;
  double b;

  cout<<"I will calculate basic operations of two numbers"<<endl;

  cout<< "Please introduce the first number  "; cin >>a;

  cout<< "Please introduce the second number  "; cin>>b;

  cout<<"The sum of the two numbers is  "<< addition(a,b)<<endl;
  cout<<"The sustraction of the two numbers is "<< sustraction(a,b)<<endl;
  cout<<"The product of the two numbers is "<<product(a,b)<<endl;
  cout<<"The division of the two numbers is "<<division(a,b)<<endl;
  cout<<"The remainder of the division is "<<remainder(a,b)<<endl;

  return 0;
}

As you can see, the functions will always be on top and then when we are ready to use them, we just have to call them inside the int main(){}. 

Here is a picture of the program running in Cygwin:

On to Functions execution

And as always, I will also be leaving this codes in my GitHub account, so if you want to check this or any other codes, you will find them here in my repository of TC101 Tasks.

Hope you like it! Have an awesome week and remember to keep up with those crazy thoughts!

-The Admin.