Ultimate V

The Purpose

Hi im making an application using a console to find the volume and surface area of three entered variables...

Part of The Program

Code Snippet

// Declare variables.

static double width, height, depth;

static string theSurfaceArea, theVolume;

// Ask the user to enter the variables

Console.WriteLine("Please enter the the following...\n");

Console.Write("Width: "); width = Console.ReadLine();

Console.Write("Height: "); height = Console.ReadLine();

Console.Write("Depth: "); depth = Console.ReadLine();

The Problem

It reads the width, height, and depth as strings not doubles, how do i fix this

Re: Visual C# Express Edition Consol input problems

Christopher Fleming

Well first you need to write the user's input to a string variable initially. Next, to make sure the user actually entered a numeric value, you'll want to pass that value to a method such as the one below:

public static bool IsNumeric(object Expression)
bool isNum;
double retNum;
isNum = Double.TryParse(Convert.ToString(Expression), System.Globalization.NumberStyles.Any, System.Globalization.NumberFormatInfo.InvariantInfo, out retNum);
return isNum;

If the user's input is numeric then you can use Convert.ToDouble() around the
string to convert it to the variable you want to use in your calculations.

Re: Visual C# Express Edition Consol input problems

Ultimate V

thanks for your help!! it works now