by Tibor Nagy
by Tibor Nagy

I just did #WSQ08! I was having a little trouble with functions, but I think I understand now. I used to be the best of my class at Prepa TEC programming, but now everyone is good and I felt I was way behind. I just hope I keep learning. As Ken, I think #It’sOkayToFail, since I believe that failure is the most efficient way to learn, and learning is the most efficient way to avoid failing!

Here’s my code:

#include <iostream>
using namespace std;

int sum(int x, int y){
int a=x+y;
return a;
}
int difference (int x, int y){
if (x<y){
int b=y-x;
return b;}
else{
int c=x-y;
return c;}
}
int product(int x, int y){
int d=x*y;
return d;
}
int division(int x, int y){
if (x<y){
int e=y/x;
return e;
}
else{
int f=x/y;
return f;
}
}
int remainder(int x, int y){
if (x<y){
int g=y%x;
return g;
}
else{
int h=x%y;
return h;
}
}

int main()
{
int a,b,c,d,e,f,g;
cout <<“write a number: “;
cin>>a;
cout <<“Write another number: “;
cin>>b;
c=sum(a,b);
cout<<“The sum of both numbers is= “<<c<<endl;
d=difference(a,b);
cout<<“The difference of both numbers is=”<<d<<endl;
e=product(a,b);
cout<<“The product of both numbers is= “<<e<<endl;
f=division(a,b);
cout<<“The result of the division of both numbers is= “<<f<<endl;
g=remainder(a,b);
cout<<“The remainder is= “<<g<<endl;

return 0;
}

CC BY 4.0 On to functions by Mferflores is licensed under a Creative Commons Attribution 4.0 International License.