c# - Why is my foreach printing out 2 char? -
i trying create encryption (ceasar) education , reason can't seem understand why simple code (so far) making such hazzle
static void main(string[] args) { string word; int key = 0; console.writeline("write messages"); word = console.readline(); console.writeline("enter key cypher"); key =int.parse(console.readline()); encrypt(word, key); } static void encrypt(string message, int key) { foreach (char otherword in message) { console.write(otherword); console.read(); } } if write example test after "write messages" , place string word , use in function encrypt, should output
t e s t but whatever god forsaken reason output
t es t and dont understand why.
you want use console.writeline(otherword); then. spacing of newlines in output dependent on key press after console.read(); line. (for example, if press [enter], newline, if press a not.)
you should use console.readkey(true); rather console.read(); method of separating output, make key press not show up.
Comments
Post a Comment