views:

108

answers:

3

I have :

    NSInteger dollarrow = [ValuesPicker selectedRowInComponent:kDollar];

    NSString *dollar = [dollarlist objectAtIndex:dollarrow];

   double converteddollar=0;

I want to do a for loop on this and get the value in double , I am trying this :

    for(dollar=1;dollar<=99;dollar++)
    {
    converteddollar = converteddollar + 2;
    }

Now the dollar contains NSString how do I convert into double to do the operation successfully and then

NSString *message = [[NSString alloc] initWithFormat:@"%0.2f",converteddollar];

I am getting warnings and the app is crashing .. How can I correct it . I am learning Objective C please help . Thankyou . Sorry I did not want == i just wanted to use =

A: 

Lots of errors...

NSInteger dollarrow = [ValuesPicker selectedRowInComponent:kDollar];

The selectedRowInComponent: method is a member method. Not a static one. You need to call it on an instance.

== is a comparison operator. What you want is certainly an assignment, with a single =sign.

You declare a pointer to a NSString object. But it's not initialized.
You should also use a temporary double variable for your loop.

I don't understand what your loop is supposed to do. Can you explain a little bit?

Macmade
well basically I want to get the dollar value from the selected picker value .. then want to use the value to set the converteddollar to +2 of the value which it was previously , assume that the converteddollar value as of now is 0 .thankyou
A: 
taskinoor
the 'i' in my case is an NSString which was extracted from the UIPicker.
convert it to a int. NSInteger i = [str intValue];
taskinoor
A: 

NSString *dollar = [dollarlist objectAtIndex:dollarrow];

double converteddollar = [dollar doubleValue]; should work (no need for you for loop)

Niko