I'm having a horrible issue with this exercise in this book. It sees no errors unless I try to run it or go into debug mode. in Debug mode it says

" line 39 Input string was not in a correct format."

If I run it without debugging, it crashes in the command prompt window, lol.

I'm using Visual Studio 2010 Pro, 64 bit windows 7 home premium.

The program is simply to figure out how much the carpet will cost me per square yard.(It's a book example of a real life scenario, I'm not really buying carpet....)

The link to my code is here, this website seems to color odd words in the code so I used pastebin instead. Please help!


The repaired code: (and I added the round function, to 2 decimal places):

class Program
        static void Main(string[] args)
            const int SQ_FT_PER_SQ_YARD = 9;
            const int INCHES_PER_FOOT = 12;
            const string BEST_CARPET = "Berber";
            const string ECONOMY_CARPET = "Pile";

            int roomLengthFeet = 12,
            roomLengthInches = 2,
            roomWidthFeet = 14,
            roomWidthInches = 7;

            double roomLength,

            roomLength = roomLengthFeet +
                roomLengthInches / INCHES_PER_FOOT;
            roomWidth = roomWidthFeet +
                roomWidthInches / INCHES_PER_FOOT;
            numOfSquareFeet = roomLength * roomWidth;
            numOfSquareYards = numOfSquareFeet /

            carpetPrice = 27.95;
            totalCost = numOfSquareYards * carpetPrice;            
            totalCost = Math.Round(totalCost, 2);
            string strTotal = String.Format("{0:C}", totalCost);            
            Console.WriteLine("The Cost of {0} is {1}", BEST_CARPET, strTotal);

            carpetPrice = 15.95;
            totalCost = numOfSquareYards * carpetPrice;
            totalCost = Math.Round(totalCost, 2);
            strTotal = String.Format("{0:C}", totalCost);   
            Console.WriteLine("The cost of {0} is {1}", ECONOMY_CARPET, strTotal);

This article has been dead for over six months. Start a new discussion instead.