wat's wrong???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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);
}
}
}
}
 
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.
 
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.
 
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;
 
Hello alyssa,
else if (chksurchargeGiven.Checked==true ()) means that when the checkbox
is checked==>true,then the cost will be computed

No it doesn't. See the open-parenthesis and close parenthesis after the
keywork 'true'? You are telling the compiler that you want to call a
method. However, the keywork 'true' is an invalid method name. That's what
I was asking about.

This is a compile-time error. Remove the extra parentheses:

else if (chksurchargeGiven.Checked==true)

Also, when I compile your code, I get all kinds of errors in the Convert To
Blocks method.
I fixed the errors and got this code:

public void ConvertToBlocks ()
{
start_time = (int) Math.Round ((double)((call_start/100)*60*60));
end_time = (int) Math.Round ((double)((call_end/100) * 60)*60);
}

Caveat: I may not have fixed the errors *correctly*. I simply fixed the
syntax errors using one of many possible ways. IOW, I guessed. If you are
debugging and you find an error in this code, feel free to fix it again.

Hope this helps,
--
--- 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.
 
Back
Top