Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-15-2011, 03:34 PM   #1 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 3
jamiescale is on a distinguished road
Default Math Formula w/ multiple "if"'s?

Newbie here...I'm working on my 1st iphone app and have hit a snag.

Basically, there are 4 text input fields. the first 3 are for numbers (num1, num2, num3), the 4th one (call it form1) someone selects a number between 1 and 3 for 3 different formulas to be applied to those other 3 numbers.

ex: if someone selects "1" for form1, then the formula is:
((num1-num3)*num2))*.8
if someone selects "2" for form1 then its:
((num1-num3)*num2))*.5
if someone selects "3" for form1 then its:
((num1-num3)*num2))*.3

I'm completely stuck on the syntax and like I said, ultra-new to sw dev in general so any help would be GREATLY appreciated.

Thanks in advance!
jamiescale is offline   Reply With Quote
Old 02-15-2011, 03:42 PM   #2 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Code:
switch (text3.text.intValue) {
   case 1:
      //do stuff
   break;
  
   //etc...
}
more here: The Objective-C switch Statement - Techotopia
baja_yu is offline   Reply With Quote
Old 02-15-2011, 05:28 PM   #3 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 3
jamiescale is on a distinguished road
Default

Quote:
Originally Posted by baja_yu View Post
Code:
switch (text3.text.intValue) {
   case 1:
      //do stuff
   break;
  
   //etc...
}
more here: The Objective-C switch Statement - Techotopia

Not sure I follow you. I'm real new to programming/iphone SDK so is there any way you could put it in plainer English?
jamiescale is offline   Reply With Quote
Old 02-15-2011, 06:45 PM   #4 (permalink)
Reading the Documentation
 
baja_yu's Avatar
 
Join Date: Sep 2010
Location: 45.255019,19.844908
Posts: 5,414
baja_yu has a spectacular aura about
Default

Check the tutorial in the link that I posted, it explains how the switch statement is used.
baja_yu is offline   Reply With Quote
Old 02-15-2011, 07:26 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jamiescale View Post
Newbie here...I'm working on my 1st iphone app and have hit a snag.

Basically, there are 4 text input fields. the first 3 are for numbers (num1, num2, num3), the 4th one (call it form1) someone selects a number between 1 and 3 for 3 different formulas to be applied to those other 3 numbers.

ex: if someone selects "1" for form1, then the formula is:
((num1-num3)*num2))*.8
if someone selects "2" for form1 then its:
((num1-num3)*num2))*.5
if someone selects "3" for form1 then its:
((num1-num3)*num2))*.3

I'm completely stuck on the syntax and like I said, ultra-new to sw dev in general so any help would be GREATLY appreciated.

Thanks in advance!

If you have an input field called form1, baya's approach would look like this:

Code:
float result, multiplier;
switch ([form1.text intValue])
{
  case 1:
    multiplier = .8;
    break;

   case 1:
    multiplier = .5;
    break;

  case 1:
    multiplier = .3;
    break;
}
float value1 = [num1.text floatValue];
float value2 = [num1.text floatValue];
float value3 = [num1.text floatValue];
result = ((value1-value3)*value2))* multiplier;

Bear in mind that this code is probably not perfect. There are probably a couple of syntax errors, and the code probably won't fit into your app without some changes. Don't post back, telling me that there is this or that error when you try to compile it. I've spoon-fed you 90% of it. The last 10% is up to you.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 02-15-2011, 08:16 PM   #6 (permalink)
Registered Member
 
87vert's Avatar
 
Join Date: Sep 2010
Location: Pittsburgh
Posts: 172
87vert is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
I've spoon-fed you 90% of it. The last 10% is up to you.

LOL
__________________
Wolfador Coding
Check out my apps:
Crazy Dog Daily Log || Crazy Spouse Daily Log || iCourtReport
87vert is offline   Reply With Quote
Old 02-16-2011, 11:48 AM   #7 (permalink)
Registered Member
 
Join Date: Feb 2011
Posts: 3
jamiescale is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
If you have an input field called form1, baya's approach would look like this:

Code:
float result, multiplier;
switch ([form1.text intValue])
{
  case 1:
    multiplier = .8;
    break;

   case 1:
    multiplier = .5;
    break;

  case 1:
    multiplier = .3;
    break;
}
float value1 = [num1.text floatValue];
float value2 = [num1.text floatValue];
float value3 = [num1.text floatValue];
result = ((value1-value3)*value2))* multiplier;

Bear in mind that this code is probably not perfect. There are probably a couple of syntax errors, and the code probably won't fit into your app without some changes. Don't post back, telling me that there is this or that error when you try to compile it. I've spoon-fed you 90% of it. The last 10% is up to you.
This is perfect... I can figure the rest out from here. Thanks again!
jamiescale is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 374
8 members and 366 guests
chemistry, cpsclicker, jeroenkeij, Kirkout, PavelMik, teebee74, whitey99
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,666
Threads: 94,120
Posts: 402,898
Top Poster: BrianSlick (7,990)
Welcome to our newest member, cpsclicker
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:05 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0