0

Trying to multiply 'a' and 'b' which should be 3600. What happened? C#

I'm new and trying to learn the basics with the numbers and stuff right now why didn't it multiply to 3600 and instead got to 9506. https://sololearn.com/compiler-playground/cL05Ngs2ALTR/?ref=app

5th Jan 2025, 1:24 AM
Christopher Smith
Christopher Smith - avatar
3 ответов
+ 5
you're re-assigning 'a' and 'b' to your variables. Why? //what you expect: Console.WriteLine(72*50); //3600 //what you did: Console.WriteLine('a'*'b'); //9506 // because chars have int values: Console.WriteLine((int)'a'); // 97 Console.WriteLine((int)'b'); // 98 //what you're actually doing: Console.WriteLine(97*98); //9506 --edit-- for those reading this comment at a later date and is confused, the original code above has already been updated by the OP, so the code in question are no longer there...😅 Even the title is confusing now...
5th Jan 2025, 2:07 AM
Bob_Li
Bob_Li - avatar
+ 5
why do you think it would make it faster? Are you sure you corrected the codes properly? Also, don't use () unnecessarily. it should be something like this: int goblins_killed = 72; int goblin_exp = 50; int exp = goblins_killed * goblin_exp; int level = 1; int total_exp = level*1000; Console.WriteLine("level: " + level); Console.WriteLine ("total exp: " + total_exp); Console.WriteLine ("exp: " + exp);
5th Jan 2025, 2:20 AM
Bob_Li
Bob_Li - avatar
+ 2
Ok thanks for the help I understand now why it was like that now.
5th Jan 2025, 2:39 AM
Christopher Smith
Christopher Smith - avatar