❔ how do i convert a char to an int
i tried a bunch of different methods and none worked
62 Replies
Just cast
Angius
REPL Result: Success
Result: int
Compile: 322.110ms | Execution: 28.185ms | React with ❌ to remove this embed.
Unless you want to get
7
from '7'
, thenAngius
REPL Result: Success
Result: double
Compile: 508.428ms | Execution: 37.904ms | React with ❌ to remove this embed.
oh wait
im stupid
i dont need to just convert to int
i need to delete the last value and then convert to int
u know how?
What do you mean "delete the last value"?
if the char is r
i want to make it nothing
convert it to int
and then assign a value
what
i want to make a char with the value r to an int with the value 1
But... the value of
r
is not 1
Angius
REPL Result: Success
Result: int
Compile: 371.133ms | Execution: 24.331ms | React with ❌ to remove this embed.
It's 114
i want to make a char that is r to 1
and an int
oh wait
wait
im stupipd i think
wait
I have no idea what you're saying
Do you want to, like, create a dictionary of chars? A list of them so different chars are at different indexes?
nvm
dont mind that
i was stupid
but
i ahve another question
how do i fix it
the last if doesnt work
Why's that
-
there?you don't need to parse the console input into a char
doesnt matter now
and it doesnt work without it
it does matter because it is in your code as you shared it currently
oh its a mistake
and it still doesnt work
doesnt work without it
then fix it 🙂
bro
i dont need to fix it
because its not a problem
if i just add the char.parse
are you stupid
@ZZZZZZZZZZZZZZZZZZZZZZZZZ do you know how to fix it?
the last if
What's wrong with it?
it says CS0165 Use of unassigned local variable 'PlayerChoiceInt'
Don't be rude.
but he is
Yeah, because what will
PlayerChoiceInt
be if PlayerChoiceChar
is €
?because its not a problem and if it is he didnt even told me how to fix it
what?
Exactly what I said
yea sorry i just dont understand that
What will
PlayerChoiceInt
be, if the input char isn't R
, isn't P
, and isn't S
, but rather €
?
What will it be if the input is T
?im gonna fix it later
if you want you could simplify your code to this
But... that's why your last if doesn't work
Do you want to fix it now?
I thought you do
But if not, then why ask?
ok i fixed it now
You didn't
PlayerChoiceInt
will still be unassigned if the input is @
yea i know it just ends the program
and thats not a problem
but all the other ifs dont work
the else works fine
but the first if and the 2 else ifs dont work either
how do i check if the letter is r p or s
please elaborate on what your current question is.
how do i check if the letter is r p or sisn't clear what you are currently struggling with because you already have
if
statements doing that
at this point you seem like you need to finish the rest of your if
statements comparing the player and computer choicesthe if statement didnt work
i don't even think this will compile, PlayerChoiceInt is being compared to something when it can be potentially unassigned
nvm i fixed it i changed the strings R P and S to chars
i just need to make PlayerChoiceInt public
and i dont know how
why would you say you need to make it public? what is giving you the impression that is your issue?
you either need to assign it a default value, or make it a field which will give it a default value automatically
wdym
public
is an access modifier. thus far the code you have shared is only top level statements. top level statements cannot include access modifiersjust assign it to 0 or something?
k
So much confusion in this thread
yea
i know
i asked like 5 different questions
but i got it
the draw works
now i need to make the other wins and losses
and do you need help with those?
maybe
yea
oh wait
maybe not
i think its done
you can reduce the size of that by a lot
oh
lol
you can
||
multiple conditions together
||
is "or"ok thx
also in general you should use
else if
instead of a bunch of if
when appropriate
also to help with your code's readability you can also do this:
and later do
that is much more readable than just using 1
, 2
, and 3
thx for all the help bro and im sorry that i called you stupid
just curious, what made you want to make a rock paper scissors app in console? 🙂
oh
i had homework
and it was a challenge question
if you liked that assignment, making console games is a great way to learn. you can make more games than just rock paper scissors.
and there are plenty of examples on GitHub to help you out 😉
ok thx
ill check that out
if you want a link to some just ask. regardless, good luck learning 🙂
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.