FUCKING HELL

Jow Forums I need help
pic related
I asign 'count' to 'kgV'
Then I put my return statement down there and I get the error 'variable kgV might not have been initialized'
What the fuck am I missing??

Attached: fucking hell.png (583x411, 15K)

Other urls found in this thread:

informatik.uni-leipzig.de/~meiler/Propaed.dir/PropaedWS12.dir/Vorlesung.dir/Funktionen.dir/EuklidEinfacheVersion/ggTkgV.c
twitter.com/NSFWRedditVideo

you assign to kgv through an else branch that doesnt necessarily run, then try to return an uninitialized value

okay, makes sense. thanks.
So my IDE just warns me in the case it would´t run. The thing is: It runs always.
So what should I do?
Only use if statements?
Or is there a more elegant way?

shit. Just using if statements doesn´t work neither

Just initialize it to a value first

just return count.

Yeah, I´ve done that.
But seemingly I´m fucking retarded.
I debugged it as well.
And all it does then, is returning the asigned value at the beginning.
I´m missing something here...
hm

what are you even trying to do here, the condition for the for loop to continue is the same as one of the if conditions.
You've got your stuff all mixed up. Post question and i might do your homework because bored.

private static int kgV(int big, int small) {

int kgV = big;
int memory = big;
int ontop = small;

if (big == small || small ==1)
return kgV;

else {
for (int count = small; count != big; count = (count + ontop)) {
if (count > big)
big = big + memory;
else if (count!=big)
count=count+ontop;
else
kgV = count;
}
return kgV;
}
}

just do
int kgv = 0;
at declaration and see if it goes away or gives a different error

Jesus that is some ugly as sin code. How can you even guarantee the loop finishes and COUNT won't leapfrog BIG?
Jesus fucking christ just tell me what the function is supposed to do or I may not sleep tonight.

>what are you even trying to do here
I need to find the smalles common number for two numbers

So for example the result from 31 and 45 should be 1395

Literally re-write your code.

Attached: 1530658287554.jpg (778x900, 65K)

tell me what this is suppose to do and i'll write one for you

informatik.uni-leipzig.de/~meiler/Propaed.dir/PropaedWS12.dir/Vorlesung.dir/Funktionen.dir/EuklidEinfacheVersion/ggTkgV.c

It would seem this imbecile does not understand how If statements work. At execution the first statement is checked. If it evaluates to True the code block within it runs and then the whole tree is exited. In your code it obviously never gets to the last check under "else". It always either evaluates the first part of if statement as true or the second one (the else if).
TL;DR
The variable kgV is NEVER MODIFIED in your code. So if you don't initialize it it will shit the bed, and if you do initialize it it will always return that initialization value.

God damn it, it sucks so fucking hard to be a fucking brainlet

it looks like he doesnt understand how to use the syntax
i wonder if OP has any foundation in other languages

Thanks user. I wrote the ggT shit already yesterday. But the Professor said wen need to find a own algorithm for the kgV and we can´t use the Euklid Nigger one

How the fuck am I supposed to pass any exam. fuck.

And yes, I passed Java and C both. But that was 8 months ago and I didn´t code shit since then

>smallest common number for two numbers
what's that even supposed to mean
so like just multiply the numbers? 31*45=1395

Oh you mean the least common multiple?
It's equal to the product over the greatest common divisor.
No euclid algorithm? Okay, I'll try to write something.

fuck. I don´t even know myself anymore
i give up

multiplying the numbers gives you a common multiple, not necessarily the smallest

>Oh you mean the least common multiple?
yeah, exactly.
I thought about doing it with primes somehow, but I think that´s even more complicated.

First exercise in Algorithms and Data structures and I´m delivering like a total retard....

>Okay, I'll try to write something.
Thanks user!

is this it OP?
int lcm(int small, int big) {
int a = small;
int b = big;
while (a != b) {
while (a < b) a += small;
while (b < a) b += big;
}
return a;
}

#include
#include

// Least common multiple of two numbers.
// Defined as >= 1, over N+ only.
// Returns 0 on error.
int lcm(int num1, int num2)
{
if(num1 > num2)
{
std::swap(num1, num2);
}

if(num1 == 0)
{
return 0;
}

int lcm;
for(lcm = num2; (lcm % num1) || (lcm % num2); ++lcm)
{
// Increment until lcm is divisible by both numbers.
// Guaranteed to stop upon smallest such number.
}

return lcm;
}

Fuck yeah!
That works like a charm.
Thaks a lot user!

But now honestly: Is it normal to struggle that hard for such seemingly easy things at the beginning? I feel like back when I started out with C and didn´t know anything.

also thanks!

I mean, generally LCM(a, b) = a*b / GCD(a, b)
That's how it's generally done, you grab the GCD first. Euclid's algorithm is really fast iteratively.
>normal to struggle
Yes, just relax and write a "good enough" solution, then optimise it.

>doing kids homework for them
now he's def going to fail the exam because he didnt work it out himself
this was Jow Forums's masterplan all along to keep brainlets out of the competition

function lcd(a, b)
local r = a
while (r%a ~= 0 or r%b ~= 0) do
r = r + a
end
return r
end
print(lcd(32, 46))

Who cares dude, at least he won't waste blood pressure. He's probably in high school and in a hurry.

It's normal to overthink and overcomplicate solutions to simple problems. The best thing you can often do is to just delete the thing and start over rather than trying to make the code you're stuck with work.

I don't know who is the bigger brainlet here, OP or you.

Attached: 1470313449361.png (300x300, 67K)

>braces on the else but not the if
>local variable named the same at the method
the absolute state

Attached: 1544056159426.jpg (1008x716, 312K)

Thanks again my frens!

op, obviously
he didn't state his problem in a sane way

How do we stop people from being retarded?

whos solution did you chose

Kankermongool

Make it mandatory to read CLRS by the end of 2nd year college.

It's one of the most common baby's first homework. You must be retarded not to understand what he meant.

no u

Attached: qtcodebase.png (1129x1192, 226K)

t. retard
the braces aren't necessary for single-line conditional bodies

They aren't, but using them anyway keeps things orderly and you could cause some ambiguous behavior accidentally if you're not careful.

well of course
but the code is unreadable
not to mention when braces are used they are misleadingly placed on the same line as the conditional rather than on their own line
the argument to the conditional is a chunk of code (be it a single line or a block delimited by braces (which on its own is a single line)).

idk why a bunch of javafafs in denial keep writing languages with braces as if the braces were the colon in Python

this might work i dont know
#define erjga }
#define agjre ) {
#define prolapse int
#define kike int kgV(int big, int small
#define qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq goto
#define gaierygdhgvuhfdvaowfgiaergfuyerafguyiresbfjhgdshjgfdhjghjfdsg if (
#define isfucking +=

kike agjre prolapse kgV; prolase nigger = big; prolapse faggot = small; LOOP1: faggot isfucking small; gaierygdhgvuhfdvaowfgiaergfuyerafguyiresbfjhgdshjgfdhjghjfdsg faggot < nigger agjre qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq LOOP1; erjga LOOP2: nigger isfucking big; gaierygdhgvuhfdvaowfgiaergfuyerafguyiresbfjhgdshjgfdhjghjfdsg nigger < faggot agjre qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq LOOP2; erjga gaierygdhgvuhfdvaowfgiaergfuyerafguyiresbfjhgdshjgfdhjghjfdsg a != b agjre qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq LOOP1; erjga return a; erjga