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

sdkIQ for iPhone
($4.99)

Your First iPhone App
($1.99)

iPhone Code Generator
($9.99)

Dual Matches
($0.99)

Calcuccino Programmers' Calculator
($2.99)

SDKtoday
(free)

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, 12:33 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 36
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 12:34 AM. Reason: needed to fix something
mikelowe is offline   Reply With Quote
Old 12-13-2009, 01:23 AM   #2 (permalink)
mer
Registered Member
 
Join Date: Jun 2009
Location: San Jose, CA
Posts: 22
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, 03:08 AM   #3 (permalink)
Registered Member
 
Join Date: Dec 2009
Posts: 36
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
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: 41,860
Threads: 49,768
Posts: 213,054
Top Poster: BrianSlick (3,138)
Welcome to our newest member, gustavo7sexton
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:58 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0