Hi again! This post is about WSQ05, which can be called WSQ01.2, too. This because is the same program we did in the first assignment, but now we write a function for each calculation (which is pretty easy, by the way). The only thing you need to be careful with is the name of the variables. You cannot directly call the result of the function to print it, you need to store it in a variable first, and then print it.

**Code:**

#include

#include

using namespace std;

int sum(int n1, int n2)

{

return(n1+n2);

}

int dif(int n1,int n2)

{

return(n1-n2);

}

int pro(int n1, int n2)

{

return(n1*n2);

}

int divi(int n1, int n2)

{

return(n1/n2);

}

int mod(int n1, int n2)

{

return(n1%n2);

}

int main()

{

int n1,n2;

cout<<endl;

cout<<“This program gives you the sum, difference, multiplication, division and the remainder of two given numbers.”<<endl;

cout<<endl;

cout<<“Please insert the first number:”<<endl; cin>>n1;

cout<<“Please insert the second number:”<<endl; cin>>n2;

int s=sum(n1,n2);

int d=dif(n1,n2);

int p=pro(n1,n2);

int di=divi(n1,n2);

int m=mod(n1,n2);

cout<<“The result of the sum is “<<s<<“.”<<endl;

cout<<“The result of the difference is “<<d<<“.”<<endl;

cout<<“The result of the product is “<<p<<“.”<<endl;

cout<<“The result of the division is “<<di<<“.”<<endl;

cout<<“The remainder of the division is “<<m<<“.”<<endl;

return 0;

}

Deep

LikeLike