0

[Solved] my code works fine in C++ but not in C#?

I have already solved the "Cheer Creator" code coach problem in C++ and I wanted to convert the code to C# to expect that it will solve the cases since if-else logic are same in both but when I tested the cases in C#, it only prints out 'High Five' all in every single case! like if I put 0 it will still print out 'High Five' when it should output 'shh'. Try to put 0 in both the codes to see what I mean. https://code.sololearn.com/cnqOQaFFkJZF https://code.sololearn.com/c9m8CPopqrpM also, another question, are both of my codes readable?

10th Jun 2021, 3:33 AM
Rellot's screwdriver
Rellot's screwdriver - avatar
2 Answers
0
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { int Number_of_yards = Convert.ToInt32(Console.ReadLine()); Console.WriteLine(Number_of_yards); if(Number_of_yards <= 1) { Console.Write("shh"); } if(Number_of_yards <= 10){ for(int v = 1; v <= Number_of_yards; v++) { Console.Write("Ra!"); } } if(Number_of_yards >= 10){ Console.Write("High Five"); } } } } I tested it with the number 9 and it output 57, not sure if that was a Unicode value or what. Anyways, the solution is just to convert your input to an integer.
10th Jun 2021, 4:12 AM
George Ryan
George Ryan - avatar
0
Lol sorry about that i was testing to see if it was somehow messed up with the else if logic, but it wasn't and i forgot to replace em
10th Jun 2021, 4:45 AM
George Ryan
George Ryan - avatar