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

View Single Post
Old 12-13-2009, 01:33 AM   #1 (permalink)
mikelowe
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
 

» Advertisements
» Online Users: 251
18 members and 233 guests
ADY, apatsufas, ckgni, F_Bryant, jakerocheleau, joeallenpro, ketaskin, MarkC, michelle, Music Man, NSeven, rob.mccarthy, smethorst, Sunny46, themathminister, TheWebWizz, V_SC&, ziocleto
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,876
Threads: 89,225
Posts: 380,710
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jorge599
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:16 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.