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!

http://pastebin.com/nmfG8yd2

Recommended Answers

All 2 Replies

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,
                roomWidth,
                carpetPrice,
                numOfSquareFeet,
                numOfSquareYards,
                totalCost;

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

            //1.
            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);
            Console.WriteLine();

            //2.
            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);

            Console.Read();
        }
    }

thanks for the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.