WSQ05 – On To Functions!!!!!

What to Do:

You will go back and do WSQ01 – Fun with Numbers again.

But this time, write a function for each calculation. Each function should define two parameters (in this example of type int) and return the correct value as an integer as well.

You main program needs to ask the user for the input and then call each function to calculate the answer for each of the parts.

Progress:

fist we need to search wsq01 homework for remind how do this exercise, but now we have to change de variables into a functions.

Then we had to look for reliable sources on the subject of functions so as to know which methodology to carry out this challenge, finally as we did this task previously, we just have to change that part of functions.

CODE:

include <iostream>
using namespace std;

int sum(int x, int y){
return (x+y);
}

int Difference (int x, int y){
return (x-y);
}

int Product (int x, int y){
return (x*y);
}

int Division (int x, int y){
return (x/y);
}

int Remainder (int x, int y){
return (x%y);
}

int main()
{
int x,y;
cout << “este programa tiene una funcionalidad similar al WSQ01 pero ahora todo integrado en funciones” << endl;

cout << “teclea el primer numero a evaluar” << endl;
cin >> x;
cout << “teclea el segundo numero a evaluar” << endl;
cin >> y;

int r1 = sum(x,y);
int r2 = Difference(x,y);
int r3 = Product(x,y);
int r4 = Division(x,y);
int r5 = Remainder(x,y);

cout << “la suma de los dos numeros es: ” << r1 << endl;
cout << “la resta de los dos numeros es: ” << r2 << endl;
cout << “la multiplicacion de los dos numeros es: ” << r3 << endl;
cout << “la division de los dos numeros es: ” << r4 << endl;
cout << “el modulo o residuo de los dos numeros es: ” << r5 << endl;

return 0;
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s