This is the preamble for functions, so it is a very important task to know what we’re doing here for future works. The code is shown here below, where we defining the variables before the main function, while making the calculations in the main function.
Then we compile it on Cygwin to check for any mistakes… since it doesn’t have any, we give the program the values 13 and 5, just for fun.
And run it to see how well it does its job!
]]>This is the preamble for functions, so it is a very important task to know what we’re doing here for future works. The code is shown here below, where we defining the variables before the main function, while making the calculations in the main function.
Then we compile it on Cygwin to check for any mistakes… since it doesn’t have any, we give the program the values 13 and 5, just for fun.
And run it to see how well it does its job!
]]>This is the preamble for functions, so it is a very important task to know what we’re doing here for future works. The code is shown here below, where we defining the variables before the main function, while making the calculations in the main function.
Then we compile it on Cygwin to check for any mistakes… since it doesn’t have any, we give the program the values 13 and 5, just for fun.
And run it to see how well it does its job!
]]>Para hacer este código me apoyé en el libro y aparte me explicaron algunos amigos las dudas que tuve, sobre todo con la sintaxis.
Mi código es este:
// WSQ03 Basic math
#include <iostream>
using namespace std;
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 ” <<(x+y) <<endl;
cout <<“La resta es ” <<(x-y) <<endl;
cout <<“La división es ” <<(x/y) <<endl;
cout <<“El rsiduo de la división es ” <<(x%y) <<endl;
return 0; }
This is the code of the program:
And this is how it looks ike when you run it:
]]>#include <iostream>
using namespace std;
int main (){
int x;
int y;
cout << “Introduce un numeron”;
cin >> x;
cout << “Introduce otro numeron”;
cin >> y;
cout << “El resultado de la suma es= ” << x+y <<“n”;
cout << “El resultado de la resta es= ” << x-y <<“n”;
cout << “El resultado de la division es= ” << x/y <<“n”;
cout << “El residuo de la division es= ” << x%y <<“n”;
return 0;
}
This is the program.
I only read and with that I could do this program.
]]>using namespace std;
int main()
{
int a,b,c,d,f,g;
cout << “Dime número A” << endl;
cin >> a;
cout << “Dime número B” << endl;
cin >> b;
c = a + b;
d = a * b;
f = a/b;
g = a%b;
cout << “El resultado son los siguientes” << endl << c << endl << d << endl << f << endl << g;
return 0;
}
So here I’ll put an image about my program, and the I explain it:
Gaze at the program, try to understand it and then read this:
First of all, I ask the user to enter two integer values, because that is what I need to run the program.
Then (look at the program), I make some functions, like the sum, the difference, the product, the division and the last one, have a “%” sign, this means that the value that is going to be returned is the residual of the integer division of the two numbers (the first one over the second one).
Then I print the values on screen, in order to our user to see them, and also put a little explanation of what that value represents, because there is no point in just print numbers, no one would know from where they come from.
Okay… I think this is all for this one. If anyone have questions about how to done it, feel free to ask me.
The code for this WSQ is over here: https://github.com/hrglez/TC1017/blob/master/WSQ03%20-%20Numbers
]]>