473,386 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Please help me with the following code

Please help me with the following snippet
float withdrawal=(objgetWithdrawal is float)? (float)objgetWithdrawal :0;

float expence= (objgetSpending is float)? (float)objgetSpending :0;

lblBal.Text="Current Balance = Rs." +

(withdrawal-expence) > 0.0F? //here i am getting the error "Operator '>'
cannot be applied to operands of type 'string' and 'float'"
(withdrawal-expence).ToString():"Error Check DB";
Nov 16 '05 #1
4 1033
Hi NotYetaNurd

Put a ().ToString() around your float test, or possibly just a (). The compiler thinks you are trying to do ("Current Balance = Rs." + (withdrawal-expence)) > 0.0F, which will turn out to be string > float.

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #2
i tried this
((withdrawal-expence)> 0.0F)?

but still

Cannot implicitly convert type 'string' to 'bool'


"Morten Wennevik" <Mo************@hotmail.com> wrote in message
news:opr9sesxpgklbvpo@morten_x.edunord...
Hi NotYetaNurd

Put a ().ToString() around your float test, or possibly just a (). The compiler thinks you are trying to do ("Current Balance = Rs." +
(withdrawal-expence)) > 0.0F, which will turn out to be string > float.
--
Happy coding!
Morten Wennevik [C# MVP]

Nov 16 '05 #3
Well, your line is missing information

<statement> ? <if true> : <if false>

((withdrawal-expence)>0.0F) will be bool(ean) true or false. You are missing the information to be written.

((withdrawal-expence)>0.0F) ? "Still money left" : "Sorry dude, you spent more than you had";

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 16 '05 #4
"NotYetaNurd" wrote:
Please help me with the following snippet
float withdrawal=(objgetWithdrawal is float)? (float)objgetWithdrawal :0;

float expence= (objgetSpending is float)? (float)objgetSpending :0;

lblBal.Text="Current Balance = Rs." +

(withdrawal-expence) > 0.0F? //here i am getting the error "Operator '>'
cannot be applied to operands of type 'string' and 'float'"
(withdrawal-expence).ToString():"Error Check DB";


put () around the whole thing might solve it

( (withdrawal-expence) > 0.0F? (withdrawal-expence).ToString():"Error Check DB" )

I think as a good practice, you should really stop cramming so much into a single line. it's bad for readability, a maintainence nightmare months down the line and likely to be buggie. for example, sometimes (when you don't have the right grouping), implicit conversions could cause lines like this to evaluate to something very different from your original intension without generating errors. this is definitely not the right way to obfuscate code.
Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Alan Bashy | last post by:
Please, guys, In need help with this. It is due in the next week. Please, help me to implement the functions in this programm especially the first three constructor. I need them guys. Please, help...
1
by: Robert | last post by:
Vb.Net Make dll that contain one function. Help Please. I would like to call a function from different applications. I think i have to make a dll. I have Visual Basic.net 2003 Standard...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
3
by: promiscuoustx | last post by:
I am trying to get my program to compile, but it will not complete. At line 79 it states, cannot convert 'float()()' to 'float' in assignment. Here is my code. #include <iostream> #include...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.