Visualg - Exercise with procedure

Asked

Viewed 836 times

0

Good afternoon guys, all right?

I have an exercise in Algorithms I, and I’m stuck in a doubt. The question:

- Write a procedure that takes an integer number and prints it in the extended form. For example, for 1 the desired output is "One". The function must be able to generate the extended numbers from 1 to 15 inclusive. If a non-compliant number is received the procedure should show an error message. Also create an algorithm that reads an integer value and call the procedure created above for printing the extended number.

My code:

algoritmo "APS09"
var
   num: inteiro

procedimento FormaExtensa(n:inteiro)
var
   extenso:caracter
inicio
      escolha n
              caso "1"
                   extenso <- "Um"
              caso "2"
                   extenso <- "Dois"
              caso "3"
                   extenso <- "Três"
              caso "4"
                   extenso <- "Quatro"
              caso "5"
                   extenso <- "Cinco"
              caso "6"
                   extenso <- "Seis"
              caso "7"
                   extenso <- "Sete"
              caso "8"
                   extenso <- "Oito"
              caso "9"
                   extenso <- "Nove"
              caso "10"
                   extenso <- "Dez"
              caso "11"
                   extenso <- "Onze"
              caso "12"
                   extenso <- "Doze"
              caso "13"
                   extenso <- "Treze"
              caso "14"
                   extenso <- "Quatorze"
              caso "15"
                   extenso <- "Quinze"
              outrocaso
                   extenso <- "Número não compatível"
      fimescolha
      escreval(extenso)
fimprocedimento

inicio

      escreva("Digite um número até 15: ")
      leia(num)

      FormaExtensa(num)

fimalgoritmo

However, at the time of running, he asks to enter the correct number, however, whatever number I type, he gives an error in caso "1" and says he expected an INTEGER. I still don’t understand where he expected an integer.

Can someone help me with this? Thank you in advance.

[RESOLUTION]

I just removed the quotes from the case, as suggested in response to the post.

caso 1
                   extenso <- "Um"
              caso 2
                   extenso <- "Dois"
              caso 3
                   extenso <- "Três"
              caso 4
                   extenso <- "Quatro"
              caso 5
                   extenso <- "Cinco"
              caso 6
                   extenso <- "Seis"
              caso 7
                   extenso <- "Sete"
              caso 8
                   extenso <- "Oito"
              caso 9
                   extenso <- "Nove"
              caso 10
                   extenso <- "Dez"
              caso 11
                   extenso <- "Onze"
              caso 12
                   extenso <- "Doze"
              caso 13
                   extenso <- "Treze"
              caso 14
                   extenso <- "Quatorze"
              caso 15
                   extenso <- "Quinze"
              outrocaso
                   extenso <- "Número não compatível"
      fimescolha

1 answer

1


Guy sees if it’s not because you put double quotes "", he expects to receive a number but this being compared with a string, in case it would be like this:

escolha n:
    case 1 extenso <- "UM"
    case 2 extenso <- "DOIS"
    ...
fimescolha
  • Exactly that my friend... What a mole I scored. hahaha I thank you in the same way. I’ve even edited the post with the resolution

Browser other questions tagged

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