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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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 12-13-2009, 01:33 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 66
Question Quadratic Formula Solver Qustion

Ok, so I am a bit new with the iPhone SDK and this is getting frustrating. I am trying to build an application where the user types in the values of a,b, and c for a quadratic equation and it gives them x. so far, this is what I have

HTML Code:
- (IBAction) solve {
	
	//a is the string, afield is the text field, ia is double
	a = afield.text;	
	ia = [a doubleValue];
	
	b = bfield.text;
	ib = [b doubleValue];
	
	c = cfield.text;
	 ic = [c doubleValue];	
	
	ix1 = (-ib + sqrt((ib*ib)-4*(ia*ic)))/2*ia;
	x1 = [NSString stringWithFormat:@"%i", ix1];
	x1field.text = x1;
	
	ix2 = (-ib - sqrt((ib*ib)-4*(ia*ic)))/2*ia;
	x2 = [NSString stringWithFormat:@"%i", ix2];
	x2field.text = x2;
	
	
	x2field.text = [NSString stringWithFormat:@"%d", ix2];
	
	root = ((ib*ib)-4*(ia*ic))/2*ia;
	
	if (root == 0) {
	
		UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:@"Oh No!" message:@"There is no real answer to this equasion." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
		[alertView show];
		[alertView release];
		
	}
	
}
I don't get any errors, but the x1field and x2field values are always 0. I'm pretty sure the answer is something simple. Help would be greatly appreciated

Last edited by mikelowe; 12-13-2009 at 01:34 AM. Reason: needed to fix something
mikelowe is offline   Reply With Quote
Old 12-13-2009, 02:23 AM   #2 (permalink)
mer
Registered Member
 
Join Date: Jun 2009
Location: San Jose, CA
Posts: 28
Default

You're using "%i" and "%d" in your string formatter, both of which are expecting integers, but ix1 and ix2 look like they're doubles. Try changing them to "%f".
mer is offline   Reply With Quote
Old 12-13-2009, 04:08 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 66
Default

Quote:
Originally Posted by mer View Post
You're using "%i" and "%d" in your string formatter, both of which are expecting integers, but ix1 and ix2 look like they're doubles. Try changing them to "%f".
Thanks! that works perfectly.
mikelowe is offline   Reply With Quote
Old 01-02-2011, 05:45 AM   #4 (permalink)
Registered Member
 
Join Date: Jun 2009
Posts: 61
Default

I really doubt this works perfectly, because you have missing the parenthesis at the end of the assignment:
ix1 = (-ib + sqrt((ib*ib)-4*(ia*ic)))/2*ia;
The "2*ia" should be like this: "(2*ia)", because if you omit the parenthesis, it firstly divide the result from the left expression by 2, and then it multiply it all with 'ia'.
__________________
indie iPhone developer
Check out my website: http://www.glimsoft.com
and my iPhone app 'Quadratic Master' on the AppStore: AppStore link
!_UK@$ is offline   Reply With Quote
Old 01-03-2011, 01:59 AM   #5 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 66
Default

good call. Havent touched this project in a while. Didn't test it thoroughly.
mikelowe is offline   Reply With Quote
Reply

Bookmarks

Tags
math, quadratic, solver, trouble

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
» Stats
Members: 158,484
Threads: 89,093
Posts: 380,131
Top Poster: BrianSlick (7,091)
Welcome to our newest member, lavernwatts
Powered by vBadvanced CMPS v3.1.0

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