C# Code for a calculation
-
Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff
Sounds like a homework assignment, so here are only some hints: Create a textbox for the price and a textbox for the # of hours (a
NumericUpDown
control may be better for the latter, no string-to-number conversion required there). Create a button clicked event handler for the calculate button and do the calculation there. You can convert from the textbox string to decimal/integer via Decimal.TryParse[^] or Int32.TryParse[^] method, respectively. regards -
Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff
-
So... the schools have started again... ;) The calculation part of the code is very easy:
price = pricePerHour * hours;
So, is that really where your problem lies?Despite everything, the person most likely to be fooling you next is yourself.
-
Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff
-
Sounds like a homework assignment, so here are only some hints: Create a textbox for the price and a textbox for the # of hours (a
NumericUpDown
control may be better for the latter, no string-to-number conversion required there). Create a button clicked event handler for the calculate button and do the calculation there. You can convert from the textbox string to decimal/integer via Decimal.TryParse[^] or Int32.TryParse[^] method, respectively. regardsGreeeg wrote:
Sounds like a homework assignment
His post down further in the thread really make me suspicious, it sounds like a problem I use in my class, and the funny thing is, my class doesn't start for a few more weeks.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
Greeeg wrote:
Sounds like a homework assignment
His post down further in the thread really make me suspicious, it sounds like a problem I use in my class, and the funny thing is, my class doesn't start for a few more weeks.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
fratboy trying to repair damage to the cheat library before school restarts because a helpful student cleaner tossed them all over the summer? :laugh:
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
-
So... the schools have started again... ;) The calculation part of the code is very easy:
price = pricePerHour * hours;
So, is that really where your problem lies?Despite everything, the person most likely to be fooling you next is yourself.
Guffa wrote:
the schools have started again...
Maybe. My class doesn't start for a few more weeks, and the OP's problem sounds very similar to one of my homework problems I give out, and this particular won't be assigned until the middle of October. Sorry, no credit given to the OP for two reasons: 1. I don't accept early work, 2. Wrong language, not a C# class ;P
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
fratboy trying to repair damage to the cheat library before school restarts because a helpful student cleaner tossed them all over the summer? :laugh:
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots. -- Robert Royall
Yep. Like I just told Guffa, my very similar problem is usually assigned about mid-October for the Fall term. People may look to the assistance of my former students are going to be in for a rude surprise. After about 2 years of teaching this class, I am doing a complete overhaul of it :-\
"The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
-
P. S. //Calculate the total cost of charter by number of hours X selected yacht x the rate per hour. The above is the calculation I was thing of using. I'm having trouble coding it. Jeff
I think Guffa very kindly answered (solved) your coding dilemma. But but here it is stated another way...
HAI
CAN HAS STDIO?
I HAS A rate ITZ NUMBAR
I HAS A hours ITZ NUMBAR
LOL ducketsOwed R rate TIEMZ hours
VISIBLE ducketsOwed
KTHXBYESeriously though, are you having trouble setting up the project or what? I don't get it, your questions is solved, but you restated the question... what more do you need?
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.” -Edsger Dijkstra
-
Hi Everyone, I'm learning C# and am stuck on writing code for a calculation. Here's the parameters: Calculate and display the price. The calculations will require price per hour. My project has the customer name input, item rented input x the # of hours rented = total cost. Pressing the calculate button will perform this function. Any help here would be appreciated. Thanks jeff
*********** U need to Learn Do your homework by yoursellf ********** double total = Convert.ToDouble(TextBox_item_rented.Text) * Convert.ToDouble(TextBox_cost_per_hour.Text); TextBox_total=total.ToString(); MessageBox.Show("Total Cost for customer "+ TextBox_cust_name.Text + "= " + total); *********** U need to Learn Do your homework by yoursellf ********** :sigh: :zzz: :zzz: :zzz: