0

So I've been spending longer on this issue than I like to admit. It seems like the code below would make perfect sense, but when I get the final output of balance it generates a far from correct number that I still have not figured out the meaning behind. For example, 100 - 50 = 47 (according to my code).

Therefore, I'm trying to simply let the user input a number that is subtracted from balance. Any help would be appreciated, thank you.

int balance = 100;

int userInput = Console.Read();

balance -= userInput;
tk0019
  • 37
  • 4

1 Answers1

4

Console.Read() reads a character from the Console and will return the ASCII code of it. You can read about it here.

So if you input 50, it will read the first character: '5', and it's ASCII value is 53.

So 100 - 53 = 47.

koviroli
  • 1,422
  • 1
  • 15
  • 27
  • Thank you. Turns out I spent all my time focusing on the wrong part. Didn't even consider that. `int userInput = Convert.ToInt32(Console.ReadLine());` That updated code seems to have fixed it. – tk0019 Mar 19 '19 at 08:55