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
>>58733124
Another weird thing is, the "compiler" goes like this
Expected: equal to 2
Actual: 12
when I go 2*6.
>>58733124
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.
>>58733124
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 >>>/g/sqt or if programming related in >>>/g/dpt
>>58733124
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.
>>58733124
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.
>>58733266
Also you people are going to hard on him, he's probably retarded.
>>58733124
>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;
>>58733124
Because of no return statement.
Ditch that online garbage and buy an actual book ffs
>>58733124
>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
Anon, you are trash, this is not for you, read books first.
>>58733455
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.
>>58734268
Thanks, I wasn't really sure on how to really start.
>>58733124
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.
>>58734754
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.
>>58733124
So you wrote a multiply function that always returns 3?
Nasty. Try to get it into SystemD source and post results here.
>>58734925
Pardon, it always returns 2.
>>58733124
learncpp.com
>>58735180
he could also http://www.cplusplus.com/doc/tutorial/
>>58733266
This. I need more thread space to shill my phones