Hi
This program is a calculation program. Calculates how many bars i can cut on a 4 meters length and how many i need to buy. Anyway it works to line 20 then its there it asks how many bars i need and what i typ in there lets say 21 i get in the last line of code where it should show the result i dont know what i have done wrong.
package main
import (
"fmt"
"math"
)
func main() {
for {
fmt.Println("what is your cut length? In cm: ")
var cutlength int
fmt.Scan(&cutlength)
barlength := 400
lengtheverybar := barlength / cutlength
cutbars := math.Floor(float64(lengtheverybar))
fmt.Println("You will get", cutbars, "every 4 meters bar.")
fmt.Println("How many cut bars do you need? In pieces: ")
var lengthpercut int
fmt.Scan(&lengthpercut)
totallength := lengthpercut * cutlength
fmt.Println(totallength)
barstobuy := totallength / cutlength
fmt.Println(barstobuy)
roundbarstobuy := math.Ceil(float64(barstobuy))
fmt.Println("You have to buy", roundbarstobuy, "4 meters bars.")
}
}
PS C:\Users\skillian\source\repos\gopath\src\forum.golangbridge.org\my-calculator-program-isnt-working_19921> go run .
what is your cut length? In cm:
40
You will get 10 every 4 meters bar.
How many cut bars do you need? In pieces:
16
640
16
You have to buy 16 4 meters bars.
what is your cut length? In cm:
Is that what you’re getting? If not, can you post the output you get? If so, can you provide an example of what you’d like to see instead?
Why? shouldent barstobuy be equal to what ever the result is when this two is divided?
totallength / cutlength
Because thats what im intended with that line first it calculate totallength then it should calculate barstobuy and before it presents the end result it should round it up and present the result with this roundbarstobuy.