just noob with new question

well i am trying to learn to program on c++ with pdf course and now i got to the arithmetic operations and it asked me to build this code:



#include <iostream>

using namespace std;

int main ()
{
int x = 0;
int y = 0;

cout << "input the value of X " ;
cin >> x;
cout << " input the value of y " ;
cin >> y;

int a = x;
int b = x;
int c = x;
int d = x;
int e = x;

a += y;
b -= y;
c *= y;
d /= y;
e %= y;

cout << " x += y = " << a << endl;
cout << " x -= y = " << b << endl;
cout << " x *= y = " << c << endl;
cout << " x /= y = " << d << endl;
cout << " x %= y = " << e << endl;

}

my question is this, i just cant understand the operation, i see that i declared the a b c d e x and y as an integer, i input the value of x and y so this 2 values make all thoose operations. after this i dont understand much, i see that the value of a b c d and e became the same as x i just dont understand how for exemple a is summing with y or any other operation. what i am reading from the operation is this

a (the value i inputed in x) + ??? gives the result of y

but i know that thats not it so i am here to ask someone to help me understand, read this operations.

even if whats writen is "a plus y" to where is the result going? whats the operation telling to put the result of that operation as "a"?

i hope i made made myself clear and someone here can help me, i know its a noob question but i am trying to learn by myself and i have no one to help me around here. so thanks for anyone who read this
Last edited on
the operation
a += y;
means that a plus wiht y and put the result into a, it's the same operation as a = a + y;

You can find the explain in http://www.cplusplus.com/doc/tutorial/operators/
Compound assignment
thx i got it now :D maybe u can help me with something else, to finish the lesson i just need to rewrite this code correctly

this is the original code with all errors

#include <iostream> #include <string>

int mian ()
{
string str = "Hello world!"
cout << str << endl;
cout << float x = 5.0f * str << end;
int 65num = 65;
cout << " 65num = " << 65num << endl;

}

this is what i coud solve


#include <iostream>
#include <string>

using namespace std;
int main ()
{
string str ;
cout << "Hello world!";
cin >> str;
cout << endl;
cout << float x = 5.0f * str << endl;
int num65 = 65;
cout << " 65num = " << 65num << endl;

}
Last edited on
Topic archived. No new replies allowed.