func PointSlope() { fmt.Print(c.CL) strx1, err := i.Prompt(c.G + "Enter x1 point\n" + c.B + ">" + c.M) u.QuitAtError(err) stry1, err := i.Prompt(c.G + "Enter y1 point\n" + c.B + ">" + c.M) u.QuitAtError(err) strm, err := i.Prompt(c.G + "Enter slope\n" + c.B + ">" + c.M) u.QuitAtError(err) //all inputs now provided, to be converted. x1, err := strconv.ParseFloat(strx1, 64) u.QuitAtError(err) y1, err := strconv.ParseFloat(stry1, 64) u.QuitAtError(err) m, err := strconv.ParseFloat(strm, 64) u.QuitAtError(err) //all data points provided and converted, now to math-a-tise. fmt.Println(c.CL, c.G+"The formula is") fmt.Println("y = m(x) + b") u.Spacer(3) //to find "b" fmt.Println(y1, " = ", m, "(", x1, ") + b") filler := x1 * m //multiplies x1 and m to filler. u.Spacer(1) fmt.Println(y1, " = ", filler, " + b") fmt.Println("-", filler, "---------------|") //Shows subtraction u.Spacer(1) b := y1 - filler fmt.Println(c.B2+"b = ", b) u.Spacer(3) fmt.Println(c.B3+"y = ", m, "(x) + ", b) u.Go(1) //prints out completed statment, ends function }
func main() { done := false for done == false { fmt.Println(c.CL+c.B3+"Welcome to Solvr ", c.V, "α 1.0.0") fmt.Println(c.B2 + "Select a mode by typing the assosiated key in red") u.Spacer(2) fmt.Println(c.R+"{add}", c.G, "Basic mathmatics (add, subtract, multiply, devide)") fmt.Println(c.R+"{mxb}", c.G, "Slope solver (y=m(x)+b)") fmt.Println(c.R+"{soe}", c.G, "Systems of equations (y=m(x)+b, y=m(x)+b)") //fmt.Println(c.R+"{alg}", c.G, "Simple algebra (10 + 5x = 6x)") //fmt.Println(c.R+"{src}", c.G, "See the github source code (this will launch a webpage in your browser)") fmt.Println(c.R+"{fin}", c.G, "Exit program") mode, err := i.Prompt(c.M + ">" + c.B) u.QuitAtError(err) use := strings.ToLower(mode) switch use { case "add": simple.Function() case "mxb": slope.Function() case "soe": equ.Function() case "alg": fmt.Println(c.G + "Not a feature yet") case "src": fmt.Println(c.G + "Not a feature yet") case "fin": fmt.Println(c.G + "Ok! Bye!") done = true default: fmt.Println(c.G + "Not a valid statement") } } }
func Function() { fmt.Println(c.CL+c.B3+"Welcome to the System of Equations module", c.V, "β 1.0.0") fmt.Println(c.B2 + "Make sure you have a slope and y-intercept for all of the lines.") fmt.Println(c.B2 + "If you don't know your decimals, here's a key:") fmt.Println(c.G + "1/2 = .5, 1/3 = .333, 1/4 = .25, 1/5 = .2, 1/6 = .167, 1/7 = .143, 1/8 = .125, 1/9 = .111, 1/10 = .1") fmt.Println(c.B2+"If you do not have all equation's slope and y-intercept, type", c.R, "no"+c.B2+".") fmt.Println(c.G+"If you do, type", c.R, "yes"+c.G+".") fmt.Println() check, err := i.Prompt(c.M + "> " + c.B) u.QuitAtError(err) if check == "no" { form.Function() } //defines the first slope fmt.Println(c.CL + c.G + "Enter first slope.") filler, err := i.Prompt(c.M + "> " + c.B) u.QuitAtError(err) m1, err := strconv.ParseFloat(filler, 64) u.QuitAtError(err) //defines the first intercept fmt.Println(c.CL + c.G + "Enter first y-intercept.") filler, err = i.Prompt(c.M + "> " + c.B) u.QuitAtError(err) b1, err := strconv.ParseFloat(filler, 64) u.QuitAtError(err) /* * Now to define the second set */ //defines the second slope fmt.Println(c.CL + c.G + "Enter second slope.") filler, err = i.Prompt(c.M + "> " + c.B) u.QuitAtError(err) m2, err := strconv.ParseFloat(filler, 64) u.QuitAtError(err) //defines the second intercept fmt.Println(c.CL + c.G + "Enter second y-intercept.") filler, err = i.Prompt(c.M + "> " + c.B) u.QuitAtError(err) b2, err := strconv.ParseFloat(filler, 64) /* * At this point, we break and check for paralell & exact same lines */ if m1 == m2 && b1 != b2 { fmt.Println(c.CL + c.G + "The answer is...") fmt.Println(c.Y + "No solution, the lines are paralell") } else if m1 == m2 && b1 == b2 { fmt.Println(c.CL + c.G + "The answer is...") fmt.Println(c.Y + "All numbers on either line, they are the same.") } else { //Now that there isn't a chance of the program running forever or not at all, //We put in some user-defined braces for decimals, then guess we shall! fmt.Println(c.CL + c.B2 + "up to how many decimal places should we look for the answer?") fmt.Println(c.B3 + "WARNING! MORE DECIMAL PLACES WILL MAKE YOUR COMPUTER WORK EXPONENTIALLY HARDER AND TAKE MORE TIME!\nMORE THAN 3 POINTS IS AT YOUR OWN RISK!") filler, err = i.Prompt(c.M + "> " + c.B) //Now to change this into a .00X format... anotherBsFiller, err := strconv.ParseFloat(filler, 64) u.QuitAtError(err) someBsFiller := anotherBsFiller * -1.0 const decimalPlace float64 = math.Pow(10, someBsFiller) fmt.Println("LINE 118") fmt.Println(decimalPlace) //The superguess function above is used x, y := guessForever(decimalPlace, m1, b1, m2, b2) // fmt.Println(c.CL + c.G + "The point of interseption is...") x32 := strconv.FormatFloat(x, 'E', -1, 32) y32 := strconv.FormatFloat(y, 'E', -1, 32) fmt.Println(c.Y + "(" + x32 + "," + y32 + ")") u.Go(1) } }
func TwoPoints() { fmt.Print(c.CL) strx1, err := i.Prompt(c.G + "Enter x1 point\n" + c.B + ">" + c.M) //assigns a command-line input to strx1. //i.Prompt returns a string "strx1" and an error "err" u.QuitAtError(err) //Tests if there is an error in the input, and halts the program before it crashes stry1, err := i.Prompt(c.G + "Enter y1 point\n" + c.B + ">" + c.M) u.QuitAtError(err) strx2, err := i.Prompt(c.G + "Enter x2 point\n" + c.B + ">" + c.M) u.QuitAtError(err) stry2, err := i.Prompt(c.G + "Enter y2 point\n" + c.B + ">" + c.M) u.QuitAtError(err) //provides the data values. will be converted next 4 lines. "i" pulls from my input function //variable err will be processed on-site w/ the input function next version. x1, err := strconv.ParseFloat(strx1, 64) //Converts strx1 in to a 64-bit float. u.QuitAtError(err) y1, err := strconv.ParseFloat(stry1, 64) u.QuitAtError(err) x2, err := strconv.ParseFloat(strx2, 64) u.QuitAtError(err) y2, err := strconv.ParseFloat(stry2, 64) u.QuitAtError(err) /* *Now for something to actually happen! all variables have been declared! */ fmt.Println(c.CL + c.G + "The Formula is:" + c.R) fmt.Println(c.B1, "y2 - y1") fmt.Println(c.B1, "-------") fmt.Println(c.B1, "x2 - x1") u.Spacer(3) //adds three lines blank diffrence. fmt.Println(c.R, y2, "-", y1) fmt.Println(c.G + "-----------") fmt.Println(c.R, x2, "-", x1) //Prints out an incomplete equation u.Spacer(2) num := y2 - y1 den := x2 - x1 //the numerator and denominator of the equation. fmt.Print(c.R) fmt.Println(num) fmt.Println(c.G + "-----") fmt.Print(c.R) fmt.Println(den) u.Spacer(2) if den == 0 { fmt.Println(c.B2, "The slope is undefined") } else { m := num / den fmt.Println(c.B3, "The slope is ", m, ".") u.Go(1) ///////////////////////////////////// //adds a break and clears the page.// ///////////////////////////////////// fmt.Println(c.G + "Our y-intercept equation is:") fmt.Println(c.B1, "y = m(x) + b"+c.G) //all data points provided and converted, now to math-a-tise u.Spacer(3) //to find "b" fmt.Println(y1, " = ", m, "(", x1, ") + b") filler := x1 * m //multiplies x1 and m to filler fmt.Println(y1, " = ", filler, " + b") fmt.Println("-(", filler, ")---------------|") //Shows subtraction u.Spacer(1) b := y1 - filler fmt.Println(c.B2, "b = ", b) u.Spacer(3) fmt.Println(c.B3+"y = ", m, "(x) + ", b) u.Go(1) //prints out completed statment, ends function } }