#Accessing a struct in a function and reassigning a variable

30 messages · Page 1 of 1 (latest)

loud turtleBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.

lunar fossil
#

334-55-3214;

vernal ermine
#

Also I would appreciate it if you point me in the right direction, rather than giving me the answer outright, because I want to learn to become a better programmer

lunar fossil
#

thats not a valid integer

vernal ermine
#

I see, but thats not the issue

#

I am just testing my code, and want to fix my salary generator atm, that was just a placeholder value

lunar fossil
#
    if (s.department = HR) {
        return 20000;
    }
#

bonus points if you use a switch case instead of ifelse

vernal ermine
#

Just curious, why is it return in the function instead of reassigning the salary variable?

lunar fossil
#

well because you assign it here Charles.salary = salaryGenerator(Charles);

vernal ermine
#

Also, that did not seem to work for me, unless I did something wrong

lunar fossil
#

wouldnt make much sense if you assign and change the struct

#

also youd have to pass it as a pointer

#

if you dont return

vernal ermine
#

Even when returning my value is 0 though

lunar fossil
#

do you know the difference between = and ==?

vernal ermine
#

Ohhhhh

#

I was assigning instead of comparing

#

That went over my head, thank you for that

lunar fossil
#

yea and that assigment just so happened to have a value of 0

#

because HR is the first identifier in enum

vernal ermine
#

Damn, I didnt even think about why I was getting a 0 in the first place but that totally makes sense

#

Yep

#

HR just happens to be the first enumation which is 0

#

Thank you for your help nekro

#

I just started programming a few days ago so im very new to it all

#

!Solved

#

!solved

loud turtleBOT
#

[SOLVED] Accessing a struct in a function and reassigning a variable

loud turtleBOT
#

Accessing a struct in a function and reassigning a variable