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;
Another weird thing is, the "compiler" goes like this Expected: equal to 2 Actual: 12
when I go 2*6.
Jaxon Lopez
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.
Wyatt Bennett
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
Eli Lopez
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.
Eli Diaz
try to figure out what the significance of a function signature is.
Camden Peterson
Also, go to a learn programming subreddit for retarded questions like this, you're wasting board space.
Aaron Ortiz
>Reddit
Also you people are going to hard on him, he's probably retarded.
Brody Cox
>fucks up literal babby's first function just stick to HTML kiddo
Elijah Parker
Jesus christ all you have to do is return it. It's not a * b; it's return a * b;
William Cooper
Because of no return statement.
Ditch that online garbage and buy an actual book ffs
Bentley Reed
>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.
Jason King
Oh fuck me.
So yeah sorry everyone, just need to check again the basics, I guess.
Christopher King
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.
Kayden Morris
>Select PHP >insert worlds simplest reverse shell >it works
wew lad.
Camden Murphy
Thanks, I wasn't really sure on how to really start.
Carson Moore
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.
Andrew Gonzalez
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.
Ethan Wood
So you wrote a multiply function that always returns 3?
Nasty. Try to get it into SystemD source and post results here.