I wanna start learning C++ so I checked the various sites that give somekind of Teaching Scheme

I wanna start learning C++ so I checked the various sites that give somekind of Teaching Scheme.

Went to CodeWars, this pops in and I can't figure out why it doesn't execute properly.
Never coded a damn thing in my whole life apart from HTML and some PHP a long time ago.

Shouldn't it be something like this?


int multiply(int a, int b)
{
int result;
a = 2;
b = 1;
result = a * b;

return result;
}


The site then goes like this:

Expected: equal to 12
Actual: 2

Other urls found in this thread:

cplusplus.com/doc/tutorial/
twitter.com/NSFWRedditImage

Another weird thing is, the "compiler" goes like this
Expected: equal to 2
Actual: 12

when I go 2*6.

You pass numbers into a function, then define them in the function as something else. For example, if I ran multiply(3,5), I'd expect to get 15.

why are you setting a and b
they are set in the function call

and don't open dumb threads like this in the future
post in or if programming related in

It probably runs random numbest into A and B to test if your code works, but you have done stupid ass fucking decision and manually rewritten variables, so it fails every time.

try to figure out what the significance of a function signature is.

Also, go to a learn programming subreddit for retarded questions like this, you're wasting board space.

>Reddit

Also you people are going to hard on him, he's probably retarded.

>fucks up literal babby's first function
just stick to HTML kiddo

Jesus christ all you have to do is return it.
It's not a * b; it's return a * b;

Because of no return statement.

Ditch that online garbage and buy an actual book ffs

>CodeWars
>Go there
>Sign up
>This is literally the first thing that shows up when you sign up
>You can't sign up without completing this simple puzzle

user, you are trash, this is not for you, read books first.

Oh fuck me.

So yeah sorry everyone, just need to check again the basics, I guess.

If this is the first introduction to "learning" this site gives you - it is trash.

You need to think through your code step by step to see why it is failing, but you don't have the most basic knowledge you need to do that properly - programming requires a certain understanding of fundamentals and syntax.

Try to find something that starts you off there and you'll both learn faster and save a lot of headache later.

There are a lot of great programming introduction textbooks and courses online, I'd read the OP in /dpt/ or look for a list of good resources on reddit.

GL.

>Select PHP
>insert worlds simplest reverse shell
>it works

wew lad.

Thanks, I wasn't really sure on how to really start.

you should have gotten a compiler warning.

You are trying to overwrite the inputs of the function.
If you are going for a functional programming stile, you should never the state inside a function.

If you want to overwrite the values, use a reference to the values.

int mul(int &a, int &b){
..
}

would work.

followup: I see that you do not get a warning, you should use.
int mul(const int a, const int b){
...
}
to get the error.
Adding const to things you do not want to modify is good practice as you let people know that the inputs will remain unchanged and shouldn't be changed.

So you wrote a multiply function that always returns 3?

Nasty. Try to get it into SystemD source and post results here.

Pardon, it always returns 2.

learncpp.com

he could also cplusplus.com/doc/tutorial/

This. I need more thread space to shill my phones