[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

I wanna start learning C++ so I checked the various sites that

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 23
Thread images: 1

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
>Reddit

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
Thread posts: 23
Thread images: 1


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.