Can anyone help figure out what I am doing wrong? I'm trying to pass value and calculate cost
using System;
namespace Lab4
{
class Carpet
{
static void Main()
{
// Declaring Variables
double cost=0;
double price=0;
GetLength(length);
GetWidth(width);
GetPricePerSquareFeet(price);
CalcCostOfCarpet(length, width, price, cost);
DisplayCostOfCarpet(cost);
}
static double GetLength(double length)
{
string userin;
Console.WriteLine("Please enter Length:");
userin = Console.ReadLine();
length = Convert.ToDouble(userin);
return length;
} //end GetLength
static double GetWidth(double width)
{ // start GetWidth
string userin;
Console.WriteLine("Please enter Width:");
userin = Console.ReadLine();
width = Convert.ToDouble(userin);
return width;
}// end GetWidth
static double GetPricePerSquareFeet(double price)
{ // start GetPricePerYard
string userin;
Console.WriteLine("Please enter Price per square yard:");
userin = Console.ReadLine();
price = Convert.ToDouble(userin);
return price;
} // end GetPricePerSquareYard
static double CalcCostOfCarpet(double length, double width, double price, double cost)
{ // start calculate carpet
cost = (length * width) / 9 * price;
return cost;
}// end calculate carpet
static void DisplayCostOfCarpet(double cost)
{ // start DisplayCostOFCarpet
Console.WriteLine("Cost of Carpet{0:C}",cost);
Console.WriteLine("Press Return to Continue");
Console.ReadLine();
} // end DisplayCostOfCarpet
}
Help with C# Code please?
Not to be picky but you have too many spaces in your
code.
Also starting comments before or after a brace is a no-no ^_^
int fuc()
{//comment
do something...
}//comment
That's a little hard to read, even with the spaces.
int func()
{
//comment
do something
//comment
}
or the quick coder's way:
//comment
int func(){
do someting
}
//comment
Compact, neat, and very easy to read. It makes debugging
easier on so many levels.
Formatting ftw.
=)
Reply:using System;
namespace Lab4
{
class Carpet
{
static void Main()
{
// Declaring Variables
double cost = 0;
double price = 0;
double length = GetLength();
double width = GetWidth();
GetPricePerSquareFeet(price);
CalcCostOfCarpet(length, width, price, cost);
DisplayCostOfCarpet(cost);
}
static double GetLength()
{
string userin;
Console.WriteLine("Please enter Length:");
userin = Console.ReadLine();
double length = Convert.ToDouble(userin);
return length;
} //end GetLength
static double GetWidth()
{ // start GetWidt
string userin;
Console.WriteLine("Please enter Width:");
userin = Console.ReadLine();
double width = Convert.ToDouble(userin);
return width;
}// end GetWidth
static double GetPricePerSquareFeet(double price)
{ // start GetPricePerYard
string userin;
Console.WriteLine("Please enter Price per square yard:");
userin = Console.ReadLine();
price = Convert.ToDouble(userin);
return price;
} // end GetPricePerSquareYard
static double CalcCostOfCarpet(double length, double width, double price, double cost)
{ // start calculate carpet
cost = (length * width) / 9 * price;
return cost;
}// end calculate carpet
static void DisplayCostOfCarpet(double cost)
{ // start DisplayCostOFCarpet
Console.WriteLine("Cost of Carpet{0:C}", cost);
Console.WriteLine("Press Return to Continue");
Console.ReadLine();
} // end DisplayCostOfCarpet
}
}
now grade my answer
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment