455,465 Members | 1,511 Online
Need help? Post your question and get tips & solutions from a community of 455,465 IT Pros & Developers. It's quick & easy.

# wat's wrong???

 P: n/a hi guys.. may i know how to get the bool compatible with float?? this is what I do when the user checked the selected check box.. using System; namespace CallBillingSystem { public class phoneRate { public int call_start; //in 24 hour notation public int call_end; //in 24 hour notation public int start_time; //in seconds public int end_time; //in seconds public float call_cost; public int block_size; public float rate_per_block; public float Discount; public float tax; public float surcharge; public phoneRate() { } public void ConvertToBlocks () { start_time = Math.round (((call_start/100) *60*60); end_time = Math.round (((call_end/100) * 60)*60); } public void chargeForBillingPeriod () { if (chkdiscountGiven.Checked==true) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*Discount; } else if (chktaxGiven.Checked==true) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*tax; } else if (chksurchargeGiven.Checked==true ()) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*surcharge; } else { call_cost = call_cost + (((start_time - end_time)/block_size) * rate_per_block); } } } } Nov 16 '05 #1
4 Replies

 P: n/a Hi Alyssa, You can convert a Bool to any of the number types using float f = Convert.ToSingle(bool); //(or ToInt32, Double etc). Not quite sure I answered your question though. -- Happy Coding! Morten Wennevik [C# MVP] Nov 16 '05 #2

 P: n/a I took a look at your code. It is a class, not an event snippet. I'm not sure which method is being called. I'm guessing that you are running the "chargeForBillingPeriod" method since it is the only method that refers to the checkbox (a bad idea, btw: you should simply pass in the true/false values from the GUI when calling the method, and seperate the business logic from the GUI). I don't know where you are getting an error, except perhaps this line here: else if (chksurchargeGiven.Checked==true ()) Not sure what "true()" is. Is this the line where you are getting the error? If not, can you give us more info about what kind of error you are seeing? -- --- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer. I do not answer questions on behalf of my employer. I'm just a programmer helping programmers. -- "alyssa" wrote in message news:B9**********************************@microsof t.com... hi guys.. may i know how to get the bool compatible with float?? this is what I do when the user checked the selected check box.. using System; namespace CallBillingSystem { public class phoneRate { public int call_start; //in 24 hour notation public int call_end; //in 24 hour notation public int start_time; //in seconds public int end_time; //in seconds public float call_cost; public int block_size; public float rate_per_block; public float Discount; public float tax; public float surcharge; public phoneRate() { } public void ConvertToBlocks () { start_time = Math.round (((call_start/100) *60*60); end_time = Math.round (((call_end/100) * 60)*60); } public void chargeForBillingPeriod () { if (chkdiscountGiven.Checked==true) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*Discount; } else if (chktaxGiven.Checked==true) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*tax; } else if (chksurchargeGiven.Checked==true ()) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*surcharge; } else { call_cost = call_cost + (((start_time - end_time)/block_size) * rate_per_block); } } } } Nov 16 '05 #3

 P: n/a well, it is a the chargeForBillingPeriod is a method. So, when the user checked the Surcharge checkbox, it will call this method and pass in the value. else if (chksurchargeGiven.Checked==true ()) means that when the checkbox is checked==>true,then the cost will be computed....errmm...i'm a student and i'm learning to write the code now...so, can u teach me how to have separate business logic? the error that I get is that the (chksurchargeGiven.Checked==true ()) does not compatible with the call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*Discount; "Nick Malik [Microsoft]" wrote: I took a look at your code. It is a class, not an event snippet. I'm not sure which method is being called. I'm guessing that you are running the "chargeForBillingPeriod" method since it is the only method that refers to the checkbox (a bad idea, btw: you should simply pass in the true/false values from the GUI when calling the method, and seperate the business logic from the GUI). I don't know where you are getting an error, except perhaps this line here: else if (chksurchargeGiven.Checked==true ()) Not sure what "true()" is. Is this the line where you are getting the error? If not, can you give us more info about what kind of error you are seeing? -- --- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer. I do not answer questions on behalf of my employer. I'm just a programmer helping programmers. -- "alyssa" wrote in message news:B9**********************************@microsof t.com... hi guys.. may i know how to get the bool compatible with float?? this is what I do when the user checked the selected check box.. using System; namespace CallBillingSystem { public class phoneRate { public int call_start; //in 24 hour notation public int call_end; //in 24 hour notation public int start_time; //in seconds public int end_time; //in seconds public float call_cost; public int block_size; public float rate_per_block; public float Discount; public float tax; public float surcharge; public phoneRate() { } public void ConvertToBlocks () { start_time = Math.round (((call_start/100) *60*60); end_time = Math.round (((call_end/100) * 60)*60); } public void chargeForBillingPeriod () { if (chkdiscountGiven.Checked==true) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*Discount; } else if (chktaxGiven.Checked==true) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*tax; } else if (chksurchargeGiven.Checked==true ()) { call_cost = (call_cost + (((start_time - end_time)/block_size) * rate_per_block))*surcharge; } else { call_cost = call_cost + (((start_time - end_time)/block_size) * rate_per_block); } } } } Nov 16 '05 #4