Re: C# invalid code

Posted 17 September 2010 - 02:19 PM

Thanks for the help.
I just started programming my self. I'm not for sure what that line is trying to do. I'm trying to create a program "that prompts the user for an item price, number of items and a discount rate. the program should then calculate and print the total cost, discount cost, tax and amount due for the purchase."

Re: C# invalid code

Posted 17 September 2010 - 02:57 PM

//declare your methods like this if you don't want them to return anything (shown by return type of void). No semicolon after method declarations.
public void CalcTotalCost(){
//give your variables a type (type in below case is double which support decimal numbers between ±5.0 × 10−324 to ±1.7 × 10308 )
double totalCost;
}

If it is a console application, then you can use:

Console.ReadLine();

which reads the previous line entered into the console (I think!).

You would then assign the input that has been read to a variable so you can do calculations with it. However, the Console.ReadLine(); method returns the input as a string, therefore, to do calculations with the input, you need to convert it to a number format first.

See example below:

Console.WriteLine("Please Enter the number of items:" //asks user for input
double numberOfItems = double.Parse(Console.ReadLine()); //converts user input to double format and stores it in the numberOfItems variable

Once you have collected all the user input required,, you can use the variables (which will have all the user input stored) to do calculations like: