Link to home
Start Free TrialLog in
Avatar of smacca
smaccaFlag for Australia

asked on

Problem reading data from console

What reasons could exist for the program not allowing me (just nothing happening) to type in input for the following:

Console.Write("SHOOT OF MOVE (S-M)? ");                  
int i = Console.Read();
Avatar of NTAC
NTAC

Are you hitting the enter key?  That code works fine for me.
Are you getting a type mismatch?

Try
string inputString = Console.Read();
Console.Read returns an int representing the char they hit ..

"The next character from the input stream, or negative one (-1) if no more characters are available."

I believe you want to use Console.ReadLine()

using System;

namespace ConsoleApplication15
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            [STAThread]
            static void Main(string[] args)
            {
                  string line = Console.ReadLine();
                  Console.Write(line);
            }
      }
}


gregory you are so smart.  You answer everything.
did you also work with VistaGen ?
No, They are both sold by Syntellect, but VistaView is their older product.  We have not upgraded or migrated to VistaGen, and there is currently no discussions about doing such.

If you'd like to continue this it's
bone86_il@yahoo.com
Avatar of smacca

ASKER

Still having the problem - any chance of someone looking at project code:

  http://www.chrismccormack.com/wumpus.zip

I will increase points to 500.

If you run/debug the application you will notice my problem.

Cheers.
ASKER CERTIFIED SOLUTION
Avatar of gregoryyoung
gregoryyoung
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I think Greg has updated fine.
But for your issue, replace start function as

            public void Start()
            {
                  //display game title
                  Console.WriteLine("\nHUNT THE WUMPUS\n\n");

                  bool ok = true;
                  Console.ReadLine();  // add this
                  while(ok)
                  {
                        //display shoot or move instructions
                        Console.Write("SHOOT OF MOVE (S-M)? ");                  
                        string i = Console.ReadLine();
                                                
                        //move
                        if ( i == "m" || i == "M")
                        {
                              ok = (this.Move() != -1);                                                            
                        }

                              //shoot
                        else if ( i == "s" || i == "S")
                        {
                              this.Shoot();
                        }
                        
//                        //move
//                        if ( (char)i == 'm' || (char)i == 'M')
//                        {
//                              ok = (this.Move() != -1);                                                            
//                        }
//
//                        //shoot
//                        else if ( (char)i == 's' || (char)i == 'S')
//                        {
//                              this.Shoot();
//                        }
                  }
            }