# WSQ_05_On_To_Functions

--Originally published at Franco TC1017

This program is similar to WSQ 01 but, instead of writing the direct operations, it calculates the sum, difference, product, quotient and residue through functions.

I’d like to share my favorite quote from Bertrand Russell.

# WSQ’s a bit late

--Originally published at Programming course

So i forgot to upload my blog posts but here are all the WSQ’s we’ve done so far

The fifth one we made it’s called “On to functions”, in which basically we have to ask the user for one number and give them integers, here is the code.

I used this link that helped me understand more the for loops.

# WSQ05 – On To Functions!!!!!

--Originally published at blog de Horacio

# 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

Continue reading "WSQ05 – On To Functions!!!!!"

# Coming back to life.

--Originally published at prgrm.co

This is the blog related to WSQ05, in this program, we were asked to go back in time, to when we were just starting the course.

The original code looked like this:

```#include <iostream> /* This will include the library to call functions like
cout, cin */

using namespace std; /* This allows me to avoid writing std:: before
every function */

//Declare a whole variable
int none, ntwo;

//This is the beggining of the program.
int main (){

cout << "Insert a number: "; //Here I'm asking the user to insert a number cin >> none; //The answer of the user is stored in the previously declared variable "none"
cout << "Insert another number: "; //Here I ask the user to insert another number cin >> ntwo;

/* In this part, the program will add, subtract, multiply, divide and give back the remainder */
cout << "The sum of: " << none << " + " << ntwo << " is: " << none + ntwo << endl;
cout << "The difference of: " << none << " - " << ntwo << " is: " << none - ntwo << endl;
cout << "The product of: " << none << " * " << ntwo << " is: " << none * ntwo << endl;
cout << "The division of: " << none << " / " << ntwo << " is: " << none / ntwo << endl;
cout << "The remainder of: " << none << " / " << ntwo << " is: " << none % ntwo << endl;

}
```

As you can see, everything is in the main(), as Ken told me last class, we need to make functions because they are like lego blocks and they can be placed in different programs

Continue reading "Coming back to life."

# cout<< “Starting Again” <<endl;

--Originally published at Alvaro_246

# “ON TO FUNTIONS”

En el WSQ05 hice lo mismo que en el WSQ01,un programa que hiciera las cuatro operaciones básicas de una calculadora, pero esta vez cada una de las operaciones matemáticas que tiene el programa (Suma, Resta, Multiplicación y División) son funciones llamadas de diferente manera ” Int nombre de la función(Int valor1, valor2) { return (Formula de la función). Mi programa solo funciona con números enteros, por que utilice Int y no float.

# Homework 5 On to functions

--Originally published at Solving problems with programming

This homework is very easy, it is about a old WSQ were we have to do many operations with the same 2 variables, but instead of writting the procedures in the main function we are going to make a function to each operation and then call it int he main function

Heres the code of WSQ05 and the code of WSQ01 or the blogpost Fun With Numbers, so you can see the difference

#include <iostream>
#include <stdlib.h>
using namespace std;
int suma(int numero1, int numero2){
}
int resta(int numero1, int numero2){
}
int multiplicacion(int numero1, int numero2){
}
int division(int numero1, int numero2){
}
int residuo(int numero1,int numero2){
}
int main()
{
int num1, num2, res;
cout <<“Escribe número 1 ” <<‘\n’ ;
cin >> num1;
cout <<“Escribe numero 2 ” <<‘\n’;
cin >> num2;
res = suma(num1,num2);
cout <<“Suma = “<<res<< ‘\n’;
res = resta(num1,num2);
cout <<“Resta = “<<res<< ‘\n’;
res = multiplicacion(num1,num2);
cout <<“Producto = “<<res<<‘\n’;
res = division(num1,num2);
cout <<“Division = “<<res<<‘\n’;
res = residuo(num1,num2);
cout <<“Residuo = “<<res<<‘\n’;

}

# Volver a empezar pero ahora con funciones WSQ05

--Originally published at Hensel

En esta ocasión volví a realizar el código WSQ01, solo que ahora para cada operación utilice una función y utilice “if” para que el código determinara que operación fue designada por el usuario..

En esta parte se puede ver como realice cada operación utilizando funciones, para la operación de suma cree la función SUM_OF_NUMBERS, para la resta fue REMAINDER_OF_NUMBERS,para la multiplicación PRODUCTS_OF_NUMBERS, la división es DIVISION_OF_NUMBERS y finalmente para obtener el residuo de una división es RESIDUE_OF_DIVISION.

Aquí es en donde comienza el programa declaramos las variables num1 y num2 y se despliega un mensaje en pantalla junto con un menú, en donde el usuario deberá ingresar el numero correspondiente a la operación que quiere realizar. Una vez seleccionada la operación, esta se guarda dentro de una variable llamada “answer”, después solicita ingreses el primer numero que se guardara dentro de una variable llamada “num1”, vuelve a mostrar otro mensaje pero ahora te pide un segundo numero con el cual realizara la operación previamente seleccionada y guardara el dato ingresado en una variable llamada “num2”.

Una vez ingresados los datos, el programa comparará la variable “answer” para determinar que operación realizar. Después de encontrar la operación, llamara a la función correspondiente dentro de ese “if”. A continuación puedes ver como funciona el programa ya terminado.

# #WSQ05

--Originally published at OlafGC / Class #TC1017

#include <iostream>
#include <cmath>
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;
cin>>n1;
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;
}

# WSQ – 05, the number 1 but with a function

--Originally published at The Clueless Programmer

So this WSQ was easy because I esencially had already done this assignment. All I had to do was return to the first WSQ and just expand it by adding a function that did all of the operations that happened in the main program. So here you have the code:

#include <iostream>
using namespace std;
int sdpir (int a, int b, int res)
{
res=a+b;
cout<<“The sum of the integers is “<<res<<endl;
res=a-b;
cout<<“The difference of the integeres is “<<res<<endl;
res=a*b;
cout<<“The product of the integers is “<<res<<endl;
res=a/b;
cout<<“The integer based division is “<<res<<endl;
res=a%b;
cout<<“The remainder integer of the division is “<<res<<endl;
}
int main()
{
int num1, num2, res;