Tuesday, July 14, 2009

Can somebody explain to me that simple C# loop plz?

using System;





class UseDecimal {


public static void Main() {


decimal price;


decimal discount;


decimal discounted_price;





// compute discounted price


price = 19.95m;


discount = 0.15m; // discount rate is 15%





discounted_price = price - ( price * discount);





Console.WriteLine("Discounted price: $" + discounted_price);


}


}


The output from this program is shown here:





Discounted price: $16.9575








Sorry I am trying to find out how do we get $16.9575??


Thanks for explaining into details. I am learning C# and I have trouble to understand the for loop for some reason!1 I understand other loops but the (FOR) loop gives me issues.

Can somebody explain to me that simple C# loop plz?
it's self explantory if you look at the line





// compute discounted price


price = 19.95m;


discount = 0.15m; // discount rate is 15%





discounted_price = price - ( price * discount);





It sounds like to me you are having a mental block at the moment.





The best thing to do is to just take a breather away from what you are frustrated over and come back to it later. Sometimes it ends up clicking when you do that.





Also, when learning something new, try not to let your brain make it more complicated that it is. Are you taking classes or are you just reading books?


No comments:

Post a Comment