C#...Writing a progrm that reverse the string name you enter...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • alireza6485
    New Member
    • Jan 2009
    • 19

    C#...Writing a progrm that reverse the string name you enter...

    Hello every one:
    I have to write a program that reverse and displays the charactors of a pharase typed from the keyboard.
    This is what I wrote:
    Code:
    using System;
    public class YourName
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Enter a word");
            string word = Console.ReadLine();
            for (int i; i >0; i--)
            {
                Console.Write(word[i]);
            }
        }
    }
    Please let me know what is wrong with the code I wrote.
    Can you please re-write the code.
    Thanks
    Last edited by pbmods; Jan 24 '09, 07:18 PM. Reason: Added CODE tags.
  • alireza6485
    New Member
    • Jan 2009
    • 19

    #2
    I figure it out.All i needed to do was finding the length of the string and use in in the loop,

    Comment

    • mldisibio
      Recognized Expert New Member
      • Sep 2008
      • 191

      #3
      Yes, but you will still have a small error even after you get the string length.
      Since this is a learning assignment, you should try hard to figure it out by yourself - you will learn better that way.
      Hint: C# arrays start at (and include) index '0';

      Good luck.

      Comment

      Working...