I'm very new to programming. However, I've written a method called "succ" that's adds 1 to a given parameter. It looks like this:
int succ(int x) {
return x += 1;
}
Now I'm supposed to write another method that adds 2 numbers using my first method. This is what my attempt looks like:
int add(int x, int y) {
for(int i = 0; i < y; i++) {
succ(x);
}
return x;
}
Unfortunately it doesn't seem to work; it always returns the initial x. For example: If I type add(8,5) it just returns 8. Can someone help me? What am I doing wrong?
Thanks in advance.