Help with logic - Portugol Studio

Asked

Viewed 396 times

0

good morning! I’m trying to learn how to program, I started with logic + portugol. When trying to perform a condition exercise, the following error occurred in portugol studio:

"There are code snippets where the methodName variable may not have been started"

   programa
{
    funcao inicio()
    {
        
        cadeia nome, nomeMaior, nomeMenor
        inteiro idade, cont
        inteiro idadeMaior = 0
        inteiro idadeMenor = 999
        real soma = 0.0
        real media = 0.0
        
        para (cont = 0; cont < 10; cont++) {
            escreva("Nome: ")
            leia(nome)

            escreva("Idade: ")
            leia(idade)

            se (idade < idadeMenor) {
                idadeMenor = idade
                nomeMenor = nome
            }

            se (idade > idadeMaior) {
                idadeMaior = idade
                nomeMaior = nome
            }

            soma = soma + idade
        }

        media = soma / 10
        escreva("A média de idades é: ", media, "\n")
        escreva(nomeMenor , " tem a menor idade que é: ", idadeMenor , " anos.\n")
        escreva(nomeMaior , " tem a maior idade que é: ", idadeMaior , " anos.\n")
    }
}

Thank you in advance.

2 answers

0

I took care of it! Due to the new versions of Portugol Studio, the same is asking that values be assigned to variables.

For example:

cadeia nome = ""
inteiro idade = 0
real preco = 0.0 
  • Anderson, you can’t use a variable that wasn’t initialized, because the variable is expected to have a value to be used, and since it was not initialized, it does not contain any value. How you only set a value for the variable nomeMenor within the para but used the variable outside the para, it was necessary to ensure that the variable was initialized before the para.

  • It is a "precaution", since one should consider the possibility that your code will never execute what is within the para, keeping the variable nomeMenor worthless. ;)

-1


Anderson, you cannot use a variable that has not been initialized, because the variable is expected to have a value to be used, and since it was not initialized, it does not contain any value. Since you only set a value for the variable nameMenor inside the to but used the variable outside the to, you had to ensure that the variable was initialized

Browser other questions tagged

You are not signed in. Login or sign up in order to post.