By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,465 Members | 1,511 Online
Bytes IT Community
+ Ask a Question
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
Share this Question
Share on Google+
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" <al****@discussions.microsoft.com> 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" <al****@discussions.microsoft.com> 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

P: n/a
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.
--
"alyssa" <al****@discussions.microsoft.com> wrote in message
news:10**********************************@microsof t.com... 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.
--

Nov 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.