Project quadratic formula

this is my code for quadric formula but its not going through am I missing something
var a:Double=2.0
var b:Double=5.0

var c:Double=3.0

var root1:Double=0

var root2:Double=0

root1=(bb - 4a*c)


root1 = root1.squareRoot()


root1=root1/(2 * a)

root2 = (-b - (bb - 4ac).squareRoot()) / (2a)

print(“Root 1 is (root1)”)

print(“Root 2 is (root2)”)

Hi there,

Could you please clarify which language this is that you are requesting help for? It would be helpful in identifying the exact issues.

swift for the iOS developer

Ah okay great thank you. I’m not super familiar with Swift, but I did some fiddling around and got it to work by doing this Does this look like it helps? I essentially added in the multiplications between all the variables that didn’t have it in your code, and also changed the print function to take the root variables in. But again I’m not super familiar so some of it may have been unnecessary as I don’t know the tricks of the language.

I don’t know I think I got it but it ask to put in different numbers for the last question and they don’t work I got

Root 1 is -1.0
Root 2 is -1.5
Quadratic.swift:7:7: warning: result of call to ‘squareRoot()’ is unused
^ ~~

this is my answer for the first one but im not sure its right cause the bottom looks like an error to me

-1.0 and -1.5 are the correct roots for that function. The warning is due to root1.squareRoot() on line 7 not actually being saved anywhere. Directly below that line you have saved it back to roo1, so you can just delete the rogue line 7. See here

appreciate the help I did that but my terminal is blank now

Apologies as I’ve really just never worked on Swift too much. My code in the link I sent appears to be working so hopefully that can help a little with debugging, if not I hope someone else can jump in that has more experience and help.

got it just not the other one but i ll just go with that thanks

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.