Have a nice week.
flickr photo by Mario Klingemann
Creative Commons Public Domain
So we had to repeat WSQ 3 with a little twist. Now all of the operations we did have to be written in functions. This was one of the easiest WSQ’s looking back on it, and still very useful and basic for the understanding of C++.
Here’s the usual GitHub link: WSQ 8.
]]>Here is my code: https://github.com/Andreandc/TC1017/blob/master/WSQ08
]]>// WSQ08 Functions
#include <iostream>
using namespace std;
int suma (int p, int t) {
int s = p+t;
return s;
}
int resta (int p, int t) {
int r = p-t;
return r;
}
int division (int p, int t) {
int d = p/t;
return d;
}
int residuo (int p, int t) {
int l = p%t;
return l;
}
int main () {
int x;
int y;
cout << “Dame el primer número ” <<endl;
cin >>x;
cout << “Dame el segundo número ” <<endl;
cin >>y;
cout << “La suma es ” << suma (x,y) <<endl;
cout << “La resta es ” << resta (x,y) <<endl;
cout << “La división es ” << division (x,y) <<endl;
cout << “El residuo de la división es ” << residuo (x,y) <<endl;
return 0;
}
And the test of the code:
]]>int sum (int x, int y){
return x+y;
}
int dif (int x, int y){
return x-y;
}
int prod (int x, int y){
return x*y;
}
int divv (int x, int y){
return x/y;
}
int rem (int x, int y){
return x%y;
}
int main(){
int x,y;
cout << “Introduce el primer numero: “;
cin >> x;
cout << “Introduce el segundo numero: “;
cin >> y;
cout << “La suma es:” << endl;
cout << sum(x,y)<<endl;
cout << “La resta es:” << endl;
cout << dif(x,y)<<endl;
cout << “La multiplicación es:” << endl;
cout << prod(x,y)<<endl;
cout << “La división es:” << endl;
cout << divv (x,y)<<endl;
cout << “El residuo de la división es:”;
cout << rem(x,y)<<endl;
return 0;
}
int sum (int x, int y){
return x+y;
}
int dif (int x, int y){
return x-y;
}
int prod (int x, int y){
return x*y;
}
int divv (int x, int y){
return x/y;
}
int rem (int x, int y){
return x%y;
}
int main(){
int x,y;
cout << “Introduce el primer numero: “;
cin >> x;
cout << “Introduce el segundo numero: “;
cin >> y;
cout << “La suma es:” << endl;
cout << sum(x,y)<<endl;
cout << “La resta es:” << endl;
cout << dif(x,y)<<endl;
cout << “La multiplicación es:” << endl;
cout << prod(x,y)<<endl;
cout << “La división es:” << endl;
cout << divv (x,y)<<endl;
cout << “El residuo de la división es:”;
cout << rem(x,y)<<endl;
return 0;
}