Reputation: 11
So I want to start out by saying I'm not a programmer by any means. What I want to do is build a productivity app to help me with my everyday job. Here's what I have.
float u = ([startRate.text floatValue]);
float v = ([grossProfit.text floatValue]);
float w = y/40;
float x = (x - z);
float y = ([commissionRate.text floatValue]);
float z = x / y;
myPayRate.text = [[NSString alloc] initWithFormat:@"%3.2f", z];
So if the user enters...
u = 80
v = 800
y = 1.17
Then I need z to come out as 51, but instead I get "inf". Any help or insight is greatly appreciated.
Upvotes: 1
Views: 207
Reputation: 11
maybe rearranging your code like so would help.
float u = ([startRate.text floatValue]);
float v = ([grossProfit.text floatValue]);
float y = ([commissionRate.text floatValue]);
float w = y/40;
float x = (x - z);
float z = x / y;
myPayRate.text = [[NSString alloc] initWithFormat:@"%3.2f", z];
Upvotes: 1
Reputation: 17317
What is most likely happening here is that the value of [commissionRate.text floatValue]
is 0. Perhaps either commissionRate.text
is empty or the value isn't being converted from a string to a float correctly, probably because the value of the string is different from what you expect it to be.
Put a breakpoint on the line float z = x / y;
and examine the values of variables?
Upvotes: 1
Reputation:
You are initializing x
as x - z
. Where is x
supposed to come from?
(Perhaps that's supposed to be w - z
instead, since I don't see anything using w
?)
Upvotes: 4