+ 2
How can I change between variable types?
Please bear in mind that I am a newbie so this is me experimenting. I have written a small game that generates a random die roll which accumulates. After each roll, the player then gets the choice to roll again or stop. If at any time a 6 is rolled, the total is reset to 0 and the turn over. I have that all working fine. Now I am.trying to add a points system where thr score given = total / 10. however, I am struggling to go from a total of 24 to a score of 2.4 It must be possible! Thank you.
9 Answers
+ 11
copy and paste into code playground on your pc?
but what i posted before should work.
int total = 24; // player rolls
float score = float(total) / 10.0;
+ 10
float result = float(total) / 10.0;
Will this work?
+ 10
can u show us your code?
+ 8
According to the details provided in your question, @Jay's suggestion should work perfectly.
+ 3
I have this as an app on my phone. I will try your code tomorrow and let you know. It is.4.am in UK and I have to go to bed!
+ 2
I have my total as an Int. And set up a new variable for the score as a float.
Then I can do this:
cout << "Your total is: " << total<< " which scores "<< score;
I know there will be other ways around this, but ai want to learn how to do it as oart of my experimenting.
Thanks.
+ 2
Is there an easier way than typing it all in here?
+ 1
@Jay. Worked perfectly! Thank you. :-)
So does float(Total) temporarily change the variable from int to float?