Re: Objective C array
Re: Objective C array
- Subject: Re: Objective C array
- From: Shawn Erickson <email@hidden>
- Date: Fri, 31 May 2002 14:11:35 -0700
With that said you don't really need to store things in temporary arrays
at all. The text fields already contain and store the data, simply
iterate over them and sum up the values as needed so you can calculate
the final result you are looking for.
Also I misspoke... IB gives you an NSForm which is a sub-class of
NSMatrix.
Personally I would use a table but that can be a little more complex to
deal with at this stage. However if done correctly then your application
would be flexible in the number grades/credits. You could also place a
NSForm/NSMatrix inside of NSScrollView.
-Shawn
On Friday, May 31, 2002, at 01:56 PM, Shawn Erickson wrote:
On Friday, May 31, 2002, at 01:29 PM, Eric Conrad wrote:
classCredits[i] = [classCredit? floatValue]; <--------
classGrades[i] = [classGrade? floatValue]; <--------
The fields with the arrows pointed to them are my question, in my app
I have 10 fields for class credits and class grades each numbered
1-10. so for example classCredit1 and classGrade1. Now how can I, in
the for loop, use the current number (i) the for loop and append it
onto the end of classGrade and classCredit.
Are the fields in a NSMatrix? If not do so and then you can iterate
over them (read up on NSMatrix).
This is easy to do... in IB just drag the icon with two text fields (on
above the other) onto your window. Then option click and drag the
bottom of the text field matrix frame to grow it to the number of
fields you need.
Many other ways exist as well... using a tables, etc.
classCredits[i]+totalCredits;
classGrades[i]+totalGrades;
These do nothing... well they sum two things but the resulting value is
not stored. I think you meant to use "+=" not "+". Also it should most
likely look like this...
totalCredits += classCredits[i];
totalGrades += classGrades[i];
They can also be done in the prior for loop, no need to loop again.
gpaFinal = totalGrades/totalCredits;
Watch for totalCredits being zero here... you will get a divide by zero
error if it is. I would recommend...
gpaFinal = (totalCredits != 0) ? totalGrades/totalCredits : 0;
I had a much longer code just stating out every variable, but an array
would be so much faster in the future.
Consider using NSMutableArray instead of a simple C array.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.