0

Errors and errors

The population of rabbits at a lab doubles every year. The lab was started initially with 7 rabbits. Your program needs to calculate the number of rabbits you will have after the number of years provided as input.

30th Jun 2021, 5:51 PM
Chinmay Anand
Chinmay Anand - avatar
12 odpowiedzi
+ 2
Chinmay Anand Review the loops lesson just prior to this practice. Start with 7 rabbits. You need to loop years times (get years as an input). Inside the loop double the amount of rabbits (rabbits = rabbits * 2) and set the new amount back to the rabbits variable. After the loop output the amount of rabbits.
30th Jun 2021, 8:20 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
rabbits * 2**years
30th Jun 2021, 5:59 PM
Oma Falk
Oma Falk - avatar
+ 1
Atul [Inactive] it is simply the formula
30th Jun 2021, 7:06 PM
Oma Falk
Oma Falk - avatar
+ 1
Here is my attempt, but it says my loop syntax is wrong. Can anyone help? package main import "fmt" func main() { var years int fmt.Scanln(&years) //your code goes here start:=7 i:=2 for start := 7; i<years; i++ { start =start*i** years fmt.Println(start) } }
27th Oct 2021, 4:28 PM
Rafique
Rafique - avatar
+ 1
package main import "fmt" func main() { var years int fmt.Scanln(&years) rabbits := 7 //your code goes here for i := 0; i < years; i++ { rabbits *= 2 } fmt.Println(rabbits) }
8th May 2023, 8:34 AM
MUHAMMAD IQBAL ARRASYID
MUHAMMAD IQBAL ARRASYID - avatar
0
Post your code here
30th Jun 2021, 6:24 PM
Atul [Inactive]
0
Oma Falk Is this valid in Golang also?
30th Jun 2021, 6:29 PM
Atul [Inactive]
0
Thanks.
1st Jul 2021, 3:37 AM
Chinmay Anand
Chinmay Anand - avatar
0
It is in golang
1st Sep 2021, 6:09 AM
Rachel
Rachel - avatar
0
Can someone please help
1st Sep 2021, 6:09 AM
Rachel
Rachel - avatar
0
package main import "fmt" func main() { var years int fmt.Scanln(&years) pow := make([]int, years ) for i:= range pow { pow[i] = 7 << uint(i) // == 2**i } for _, value := range pow { fmt.Printf("%d\n" ,value) } } any one can help reduce the number of range of values to print the last number of year cause mine a whole range of years 😂😋
9th Feb 2022, 2:39 PM
princeps ludwig
princeps ludwig - avatar
0
That's insane. I don't know how they check code, or what are they formatting settings, but if they have some strict rules about styling, they should to tell about it. I've wrote solutions dozen times, trying to figure out what is the problem. And why they do not show just compilation error, and instead show just that we have an error without even showing compilation error message, like "we can tell you where you can search bug, but... don't wanna, just try again and suffer more". In mu final solution, all would not worked until i just swapped "years > 0" to "0 < years". That's my solution package main import ( "fmt" ) func main() { var years int fmt.Scanln(&years) //your code goes her res := 7 for 0 < years { res = res * 2 years = years -1 } fmt.Println(res) }
15th Aug 2024, 7:43 PM
Bakhtiyar Abdukarimov
Bakhtiyar Abdukarimov - avatar