I´ve been studying functions for a little while, in this occasion I was able to rewrite the code from the wsq03 and improve certain parts of the code with functions.
Functions are an essential tool when we are writting code, because it makes our lifes easy, just think about writting the same formula over and over again in a programm…when all you have to do is to create a function and then called it as many times as you want. Programming ain´t easy, but it´s interesting how every technological device works with some kind of source code.
Here´s my code.
#include <iostream>
#include <math.h>
using namespace std;
double addition (double a, double b){ //addition is the name of the function
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;
}
void newline(){
cout<<endl;
}
int main(){
double a;
double b;
cout<<"Hi, I´m a calculator of two numbers, I will make operations of addition, product"<<endl;
cout<<"sustraction, division and eventually calculate the remainder between the numbers you´ll give me"<<endl;
newline();
cout<<"Please, give me the first value "; cin>>a;
newline();
cout<<"Please, give me the second value "; cin>>b;
newline();
cout<<"The addition of the numbers equals to "<< addition(a,b)<<endl; //We are calling the function
cout<<"The sustraction of the numbers equals to "<< sustraction(a,b)<<endl;
cout<<"The product of the numbers equals to "<< product(a,b)<<endl;
cout<<"The division of the numbers equals to "<< division(a,b)<<endl;
cout<<"The remainder of the division equals to "<< remainder(a,b)<<endl;
return 0; //...So the programm wont return values.
}