Quote:
Originally Posted by linepisode
i changed my code like this:
Code:
float *myResult;
int myVal=txt.text;
myResult = myVal / 60;
label1.text = myResult;
But same problem again. Application halts when i enter bigger value than 60.
|
Code:
int myVal=txt.text;
This line is wrong. You can't take a string and assign it to an integer.
You had it almost right the first time, with the line
Code:
float myVal=[txt.text floatValue];
(Except that it should be "float myvalue" not "int myValue")
Now, once you calculate your new value, you want to assign it back to your label. The label.text property is a string. So, you need to convert your result, which is a float, to a string. You can't just set a string to a floating point number. It will give you a compiler warning, and may crash, depending on the value you assign.
So this line:
Code:
label1.text = myResult;
is VERY wrong. Crash your program wrong.
You need to convert your floating point value to a string.
Take a look at the method stringWithFormat. It lets you build a string out of different parts, and do format conversion while you're at it.
the expression
[NSString stringWithFormat: @"%f", 30.0]
will convert the floating point number 30 to a string, @"30". See if you can adapt that to solve your problem.