Input not working

Console.Read() Problem

Page 1 of 1

4 Replies - 379 Views - Last Post: 20 June 2009 - 04:11 PM Rate Topic: -----

#1 array  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-April 09

Input not working

Posted 20 June 2009 - 02:48 PM

This shouldnt be happening. Its the same code:


using System;

class TheProgram
{
	static Cylinder Initialize()
	{
		Cylinder CylinderType = new Cylinder(45.32, 87.43);
		return CylinderType;
	}
	static void ShowResults(Cylinder Volume)
	{
		Console.WriteLine("Enter Raidius: ");
		Volume.Radius = Console.Read();
		Console.WriteLine("Enter Height: "); // Debugger is skipping this
		Volume.Height = Console.Read(); // No display
		Console.WriteLine("Radius: {0}", Volume.Radius, "Height: {0}", Volume.Height);
		
	}
	static int Main()
	{
		Cylinder CylinderInit = Initialize();
		ShowResults(CylinderInit);
		Console.ReadLine();
		return 0;
	}
}


using System;

class Cylinder
{
	private double RadianValue = 0;
	private double HeightValue = 0;

	public Cylinder(double Radius, double Height)
	{
		this.HeightValue = Height;
		this.RadianValue = Radius;
	}
	public double Radius
	{
		get { return RadianValue;  }
		set { RadianValue = value; }
	}
	public double Height
	{
		get { return HeightValue;  }
		set { HeightValue = value; }
	}

}


And another thing, How do i get the console window to stay up without using another Console.Read() type function?

Is This A Good Question/Topic? 0
  • +

Replies To: Input not working

#2 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Input not working

Posted 20 June 2009 - 03:10 PM

To get a console program to not require a ending Console.ReadLine, I think you can try CTRL+F5. That should keep the window from closing.
Was This Post Helpful? 0
  • +
  • -

#3 array  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-April 09

Re: Input not working

Posted 20 June 2009 - 03:22 PM

View PostSixOfEleven, on 20 Jun, 2009 - 02:10 PM, said:

To get a console program to not require a ending Console.ReadLine, I think you can try CTRL+F5. That should keep the window from closing.


ah sorry, run w/o debugging haha. Slipped my mind.

But im stil having a problem with this code:

static void ShowResults(Cylinder Volume)
{
Console.WriteLine("Enter Raidius: "); // is printing
Volume.Radius = Console.Read(); // prompting me for a value
Console.WriteLine("Enter Height: "); // is printing
Volume.Height = Console.Read(); // is not prompting

//printing a value that i did not enter for the RADIUS
Console.WriteLine("Radius: {0}", Volume.Radius, "Height: {0}", Volume.Height);
}

This post has been edited by array: 20 June 2009 - 03:23 PM

Was This Post Helpful? 0
  • +
  • -

#4 SixOfEleven  Icon User is offline

  • using Caffeine;
  • member icon

Reputation: 929
  • View blog
  • Posts: 6,316
  • Joined: 18-October 08

Re: Input not working

Posted 20 June 2009 - 03:38 PM

I would try switching for Read to ReadLine. :)
Was This Post Helpful? 0
  • +
  • -

#5 array  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 28
  • Joined: 08-April 09

Re: Input not working

Posted 20 June 2009 - 04:11 PM

yes!! =)

double dValue = Convert.ToDouble( Console.ReadLine() );

I Like it (because it works) =)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1