Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is the following error.. It compiles fine but displays the errors below the code when I run the program.

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



class GlazerCalc
{

    static void Main()
    {
        double width, height, woodLength, glassArea;
        string widthString, heightString;
        // Console.ReadLine(); asks the user to input a value, and is placed in the widthString variable

        widthString = Console.ReadLine();
        width = double.Parse(widthString);

        heightString = Console.ReadLine();
        height = double.Parse(heightString);

        woodLength = 2 * (width + height) * 3.25;
        glassArea = 2 * (width * height);

        Console.WriteLine("The length of the wood is " +
        woodLength + " feet");

        Console.WriteLine("The area of the glass is " +
        glassArea + " square metres");

    }
}


Unhandled Exception: System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Double.Parse(String s)
at GlazerCalc.Main() in C:\VisualStudio\Learning\Learning\Program.cs:line 19

Debug error - An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll

Additional information: Input string was not in a correct format.
Posted

1 solution

Well, what is the value of widthString when the error occurs?

Set a break point at this line
C#
width = double.Parse(widthString);
and check the value.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900