Hello, was referred to this site from a friend of mine, I hope to stay here long =)
I have a homework that I just can't figure out how to do. I'm not sure if the teacher wrote it wrong(he is a bad typer) or if there is a way to accomplish the task.
I work in Visual C# 2010 Express - Console Application
My task is to:
Read a four digit integer, such as 5893, from the keyboard and display the digits separated from one another by a tab each. Use both integer division and modulus operator % to pick off each digit. If the user enters 4567, the output looks like:
4567
4 5 6 7
Sure I know how to seperate the numbers by using \t aswell as reading the input and displaying it to the user. But how am I supposed to 'pick off' each digit with division and the remainder operators??? Maybe he means something else, but not sure. Have to ask him if noone here knows a solution... hehe
And another question...
How do a make sure that what the user types in is a number and not a letter? Do i have to use "Char.IsLetter", because I couldn't figure out how to use it on a parsed string.
example:
string number1;
int x;
Console.Write("Please enter a number to calculate: ");
number1 = Console.ReadLine();
x = Int32.Parse(number1);
What method am I supposed to use and where do i put it in? Beacause now i only get an error and the application shuts down if I try to enter e letter....
Thanks in advance!
/Anthony
P.S. I'm very new to C# programming, though I do understand logic...