Hi, this i'm trying to make a loop that would read a list of character (including numbers) that you type in terminated by a period and that would only write the letters and ignore the other characters. How would i do this?? Thats the code ive been doing but there seem to be a problem with != operator saying it can't work with a string or int. Anybody know how i could make this work?? Ive search in many places and i can't find an answer.
This code will only give:Code:using System; class text { static void Main() { Console.WriteLine("Enter text"); string line = Console.In.ReadLine(); int text = Convert.ToInt32(line); int sum = 0; int i = 0; while (text != -9) { sum = sum + text; i++; line = Console.In.ReadLine(); text = Convert.ToInt32(line); } Console.Write("The letters are {0}", sum); Console.In.Read(); return; } }
Enter text
9949449
-9
The letters are 9949449
Is there a way i can make the sentinel finish the loop on the same line and use another character like a period. Also is there a way to make it read other values than numbers, the string would logicly work but the != doesn't accept it. And if i enter letters it crashes.
345u435hu43i$$$@@@.
The letters are uhui