Code repeater code coach - go | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Code repeater code coach - go

//My code so far: package main import "fmt" func main() { var w string fmt.Scanln(&w) var x int fmt.Scanln(&x) func repeat() { for (i=1; i <=x; i++ ){ fmt.Println(w, x) } } Does not work what is wrong with my code?

8th Dec 2021, 6:03 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar
2 Answers
+ 2
1. Try formatting your code so it is a bit easier to read and match your opening and closing curly braces, parenthesis, brackets etc. 2. You're missing the closing curly brace for the main function. 3. The repeat function should be outside and above the main function. 4. The repeat function should have the parameters for the arguments that you wish to pass in to the function and use within the body of the function. 5. The for loop doesn't use parenthesis () when initializing it. 6. The i variable should be declared and initialized using the := operator not just =. 7. Don't forget to call the repeat function, passing the needed arguments to it.
8th Dec 2021, 6:23 AM
ChaoticDawg
ChaoticDawg - avatar
0
package main import "fmt" func repeat(string w, string x) { for (i:=1;x;i++){ fmt.Println(w,x) } } func main() { var w string fmt.Scanln(&w) var x int fmt.Scanln(&x) repeat(w, x) package main import "fmt" func repeat(string w, string x) { for (i=1;x;i++){ fmt.Println(w,x) } } func main() { var w string fmt.Scanln(&w) var x int fmt.Scanln(&x) repeat(w, x) } It is still not working.
13th Dec 2021, 1:41 AM
Kim Hammar-Milliner
Kim Hammar-Milliner - avatar