Save ticket values by adding to existing amount

Asked

Viewed 57 times

0

Create a flowchart that reads from the user the value of a ticket and at the end shows: the total of the ticket and how many tickets were sold. The flowchart should only stop when typing zero in the ticket value.

It needs to store in variables totval and totquant until I type 0 in the amount to finish and show the value of tickets sold and the amount.

Var
// Seção de Declarações das variáveis 
val,quant,totval,totquant : real

Inicio
// Seção de Comandos, procedimento, funções, operadores, etc...
totval <- 0
totquant <- 0
repita

escreval("Qual valor do ingresso: ")
leia(val)
escreval("Quantos ingressos: ")
leia(quant)

totval <- val*quant
totquant <-quant


até val = 0
escreval ("valor total de ingressos é: ",totval)
escreval ("Quantidade de ingressos vendido é: " ,totquan
  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful for you. You can also vote on any question or answer you find useful on the entire site (when you have 15 points).

1 answer

1

You need to make an accumulation and are discarding the previous value in each assignment in the variables. To accumulate you have to take the current value of the variable and add with the new value you want to accumulate.

Var
    val, quant, totval, totquant : real
Inicio
    totval <- 0
    totquant <- 0
    repita
        escreval("Qual valor do ingresso: ")
        leia(val)
        escreval("Quantos ingressos: ")
        leia(quant)
        totval <- totval + val * quant
        totquant <- totquant + quant
    até val = 0
    escreval ("valor total de ingressos é: ", totval)
    escreval ("Quantidade de ingressos vendido é: " , totquan)
Fim

I put in the Github for future reference.

Browser other questions tagged

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