Prime b

Prime b

  • NA
  • 810
  • 346.9k

Convert C# to C++ help ?

Sep 20 2012 4:36 PM
You want to calculate how much it would cost to carpet a room in your new apartment. For the sake of simplicity, we will solve this problem for a single rectangular room. The program should ask its user to enter the room's length and width in feet (allowing decimal places if necessary) and then calculate the floor area of the room. Because most carpet prices are given in units of dollars per square yard, your program should ask for the carpet price that way and then convert that price to dollars per square foot before using it to calculate the overall cost of the carpet for your room in dollars. The program should display the calculated room area and the overall cost of the carpet for your room, both output rounded to a precision of two decimal places.    



Could you also tell me the program is correct, thank you!



       double width,length,carpetArea,carpetPrice,totalDue;


            Console.WriteLine("Hello");
            Console.WriteLine("Please enter width");
            width = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("PLease enter length");
            length = Convert.ToDouble(Console.ReadLine());

            Console.WriteLine("Please enter the price per square");
            carpetPrice = Convert.ToDouble(Console.ReadLine());

            carpetArea = 2 * (width) + 2 * (length);

            totalDue = carpetPrice * carpetArea;

            Console.WriteLine("The carpet area is {0}, total due is {1}$", carpetArea, totalDue);
            Console.ReadLine();

Answers (3)