Example #1
0
func main() {

	fmt.Println(c.CL)

	var points float32 = 0

	fmt.Println(c.G + "Welcome to the golang quiz!" + c.X)
	//TODO: randomise it.
	s.Go(1)
	points += q.McQuestion("There are many diffrent ways to output \"Hello World\".",
		"Which of the following prints it out on a new line?",
		"fmt.Print(\"Hello World!\")",
		"println(\"Hello World!\")",
		"fmt.Println(\"Hello World!\")", "c", 2)

	fmt.Printf(c.G+"You now have %v points!\n", points)
	s.Go(1)

	points += q.SrQuestion(`
	
package ???
				
import(
	???
	c "github.com/skilstak/go/colors"
)
		
func Main(){
	fmt.Println(c.G+"Hello, World"+c.X)
}`, "Look at the code above. What package needs to be imported?", "main", 5)

	fmt.Printf(c.G+"You now have %v points out of a possible /##.\n", points)
	s.Go(1)

	points += q.SrQuestion("In GOlang, the\"package\" notation is required for\nyour programme to work. But the package you import must be used.",
		"What should you import to get arround this?","nil",5)
	
	fmt.Printf(c.G+"You now have %v points out of a possible /##.\n", points)
	s.Go(1)

	points += q.McQuestion("Variables are like a box blah... blah... blah...", "How is a veriable explicitly 
		declared in golang?","varname := 100","varname = 100","var varname int = 100","c", 3)

	fmt.Printf(c.G+"You now have %v points out of a possible /##.\n", points)
	s.Go(1)


}
Example #2
0
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
}
Example #3
0
func SrQuestion(context string, question string, cAns string, worth float32) float32 {
	var score float32 = worth
	var done string = "false"
	for done == "false" {
		fmt.Println(c.CL)
		fmt.Println(c.G + context)
		u.Spacer(1)
		fmt.Println(c.R + question)
		u.Spacer(3)
		answer, _ := i.Prompt(c.B + ">" + c.M)
		response := s.ToLower(answer)
		answer = s.TrimSpace(response)
		response = answer

		if response == cAns {
			fmt.Println(c.G + "Correct! :D")
			//return score
			done = "true"
		} else {
			fmt.Println(c.G + "No... try again...")
			filler := score - (.1 * worth)
			score = filler
			u.Go(1)
		}
		//return score
	}
	return score
}
Example #4
0
func main() {
	fmt.Println(c.CL)
	fmt.Println(c.G + "How many dice?")
	resp, err := i.Prompt(c.B + ">" + c.M)
	if err != nil {
		s.ErrRpt(err)
	}
	time, err := strconv.Atoi(resp, 32)
	if err != nil {
		s.ErrRpt(err)
	}
	s.Go(0)

}
Example #5
0
func guessForever(decimal float64, m1 float64, b1 float64, m2 float64, b2 float64) (float64, float64) {
	x1 := 0.0
	x2 := 0.0
	y1 := m1*x1 + b1
	y2 := m2*x2 + b2
	tries := 0
	done := false
	for done == false {
		x1 += decimal
		x2 += decimal
		y1 = m1*x1 + b1
		y2 = m2*x2 + b2
		if y1 == y2 {
			done = true
		} else {
			tries++
			fmt.Println(tries)
			fmt.Println(x1)
			fmt.Println(x2)
			x1 *= -1.0
			x2 *= -1.0
			y1 = m1*x1 + b1
			y2 = m2*x2 + b2
			if y1 == y2 {
				done = true
			} else {
				tries++
				fmt.Println(tries)
				fmt.Println(x1)
				fmt.Println(x2)
				u.Go(1)
				x1 = math.Abs(x1)
				x2 = math.Abs(x2)
			}
		}
	}
	return x1, y2
}
Example #6
0
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)
	}

}
Example #7
0
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
	}
}
Example #8
0
func Standard() {
	fmt.Println(c.CL, c.G, "Sorry m9, this hasn't been devopled yet...")
	u.Go(1)
}