build errors in my function
i want to call the function until the loop ends but its giving me build errors that I'm not 100% sure how to fix.
39 Replies
post the entire file $code
To post C# code type the following:
```cs
// code here
```
Get an example by typing
$codegif
in chat
If your code is too long, post it to: https://paste.mod.gg/
sent
and which line is line 15?
a couple things
- you have a
;
at the end of the while
line, I don't think you wanted that
- coinInteraction
has a float
return type, but you're returning false
, which is a bool
also, when I paste this into sharplab I get different errors
have you saved the file you're looking at?yeah the file is saved
well the compiler isn't seeing the same file you are
so either it's not saved, or you're editing a different file
i think it was a saving issue
so with the bool to float, what I want with that block is to have it go back to the top of the loop like nothing happened
should i just have it break instead?
that's what
continue
does, break
ends the loop
but only inside the while
body, inside of functions called by while it won't workok so I have updated my code
so now the while loop should work with my if statement
coinInteraction = i - coininserted;
as coinInteraction
is a method, this makes no sense
still doesnt run but this should be on the right track?
that's not how returning from methods works
you use
return
why the assignment?
just return the expression
also, if you tried to compile that, you would see the compiler complain about assigning to an undeclared variable
ok so now I have logic issues
because the user input does not update i
it just keeps looping and doesnt use the coinInteraction method
yes it is
but you're not doing anything with the return value
so i want the return value to replace the i value in my while loop
but its not as simple as setting my method to i
how is it not?
what does "setting my method to i" mean to you?
b/c I think we have different understandings of that
something like
and why doesn't that work?
ok wait my method is set as a float
on line 25 would that be why im getting an error
ok so i changed line 25 from float to int and it runs again
but with the same logic issue
the updated code
if (coininserted != 5 || coininserted != 10 || coininserted != 25)
this will always be truehow can i make that only true when those values arent inputted
because shouldnt it not be true if the input is 5, 10, or 25
think about it why it's always true
plug a few values into that expression, see what comes out
(like in your head or on paper)
tbh im kind of stumped, my only guess would be the Int32.Parse on line 15
no, it's that if statement specifically that's the problem
and more specifically, its condition
coininserted != 5 || coininserted != 10 || coininserted != 25
think about what happens when you plug 5 into that
or 6, or 7yeah ok nvm i see it now
even if my value is one of the values i want it wont get passed the other two checks
?
yes
you meant &&, not ||
it works perfectly now thanks so much for your help
appreciate you explaining everything to me
np