Computer Science, asked by nareshnbjk9970, 9 months ago

Two friends decide who gets the last slice of a cake by flipping a coin five times. The first person to
win three flips wins the cake. An input of 1 means player 1 wins a flip, and a 2 means player 2 wins
a flip. Design an algorithm to determine who takes the cake?

Answers

Answered by luisecubero77
5

Answer:

I use Pseint

Explanation:

Algoritmo Program

opa,opb,cont,value,acuma,acumb son Entero

cont=1

mientras cont <=5

 value=azar(2)+1

 imprimir "Value of coin is: ",value

 si value == 1

  acuma=acuma+1

 SiNo

  acumb=acumb+1

 FinSi

 si acuma == 3

  imprimir "Player 1 wins"

  cont=5

 FinSi

 si acumb == 3

  imprimir "Player 2 wins"

  cont=5

 FinSi

 cont=cont+1

FinMientras

FinAlgoritmo

Algorithm Program

opa, opb, cont, value, acuma, acumb are Integer

cont = 1

while cont <= 5

        value = random (2) +1

        print "Value of coin is:", value

        if value == 1

        acuma = acuma + 1

        else

        acumb = acumb + 1

        endif

        if acuma == 3

           print "Player 1 wins"

           cont = 5

        endif

        if acumb == 3

           print "Player 2 wins"

           cont = 5

        endif

cont = cont + 1

end while

End Algorithm

Attachments:
Similar questions