Golang program i need help

my program
package main

import (

"fmt"

)

const max = 10

func main() {

var plat, dan, zdanenie float64

var n int

var polecisla [max]int

pokus := 1

sanca := 4

a := 0

sumacisla := 0

fmt.Printf("Zadajte pocet platov,ktore chcete vlozit.\n (min.1 a max.%d)\nPotom postupne zadavajte platy.\nJednotlive platy potvrzujte enterom.\n!!! Mozu byt aj desatine cisla !!!\t\t", max)

fmt.Scanf("%d", &n)

for (n <= 0) || (n > max) {

    if n <= 0 {

        fmt.Printf("\nMin.pocet platov je 1!!\n\nZadajte pocet platov ktore chcete vlozit.\n")

    }

    if n > max {

        fmt.Printf("\nMax.pocet platov je %d !!\n\nZadajte pocet platov ktore chcete vlozit.\n", max)

    }

    fmt.Printf("(Toto bol %d.pokus,zostavaju %d)\t", pokus, sanca)

    fmt.Scanf("%d", &n)

    pokus++

    sanca--

    if sanca == 0 {

        break

    }

}

if (n > 0) && (n <= max) {

    fmt.Printf("\n")

}

for a < n {

    fmt.Scanf("%d", &polecisla[a])

    sumacisla += polecisla[a]

    a++

    fmt.Scanf("%f", &plat)

    if plat > 2400 {

        dan = 0.22 * plat

        zdanenie = plat - dan

    }

    if plat <= 2400 {

        dan = 0.19 * plat

        zdanenie = plat - dan

    }

    fmt.Printf("plat %.2f \t\n", plat)

    plat++

    fmt.Printf("plat po zdaneni je:%.2f", zdanenie)

    fmt.Printf("\n")

}

}

why does my program do that if I enter the wrong input, it throws me into the console 2 times in a row? when will it fire me only once?

increase it by only one and not two

thank you for help

I do understand nothing, but it seems to work?

It would have been easier with plain english :slight_smile:

The question is in English, so why not the code? Try to do some print statements to check where exactly did the error occur and try make some edits till you get to the line causing the problem

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.