Scroll through a matrix and validate repeated numbers

Asked

Viewed 2,722 times

1

I am doing a final work in the first semester of the BCC course and I need to do a Mega Sena algorithm with the following features:

  • Maximum of 10 players
  • Each player must bet a minimum of 6 numbers and a maximum of 15 numbers
  • Valid numbers range from 1 to 60
  • Bets must not be repeated

The language used is Portugol, but we use a specific platform created by students from the University, so there are small variations in the code semantics relative to the common Visualg.

My question is only about a specific part of the code that I could not solve the betting part not repeat. If the user bets the number 1, the number 1 can no longer be used by anyone. Follows image of the code.

I suppose the solution to this problem can be solved by going through the matrix completely and checking each bet, but I couldn’t find a working method for it.

Anyone who can help, feel free to use the C language itself.

  • 1

    The requirement is even "if the user bets the number 1, the number 1 can no longer be used by anyone"? Strange that!

  • Well, that’s what I understood, but I may have misread it. The statement says "It should be noted that the numbers bet cannot be repeated and must be chosen from the values 1 to 60". I imagine I made a little mistake... Player 1 bet: 1,2,3,4,5,6.. he won’t be able to bet the 1 again, but other players can bet the 1, maybe...

  • Or maybe the restriction is that there can be no repeating numbers in the same bet (ex: 1 1 2 3 3), as in real mega sena.

  • I imagine that’s right, but I still haven’t been able to implement such validation correctly in the code.. I suppose I should go through the whole vector and check if the number is there, but every time I try, I get an error saying that the vector has not been initialized.

  • The method would be the same, but I can not help you with this code, because I know little of C and even less of Portugol. The error you quoted is from portugol or c compiler?

  • It’s from Portugol itself.

  • 1

    Try to post code instead of code image. I don’t know if Portugol has Syntax Highlight, but maybe another language will do.

  • Calango itself already has Syntax Highlight. The words in blue are the reserved words.

Show 3 more comments

1 answer

1

Before the vector[counter1][counter2] receives the bet, make a loop (to...knife) to verify that the informed bet is already inside the vector. If so, ask the user to enter the number again.

Something like:

leia(apostas);

para (contador3 de 1 ate 15) faca
       se (vetor[contador1][contador3] = apostas)
          ir para (goto) leia(apostas);      
fimpara
  • With such an implementation, I get an error "The vector variable[1][1]' has not been initialized".

  • Try to reset the vector first. loop ate 2 loop ate 15 vetor[][] = 0;

  • Try to replace in the code above the following: for (counter3 from 1 to (counter2 - 1)) knife ... This ensures that you will never test the array slots that have not yet received wagering values (not initialized)

  • Unfortunately I keep getting "uninitialized vector" errors. I imagine there is some way to after reading the 6 numbers, check inside the vector if there are repeated numbers, but I’m also getting vector not initializing error.

Browser other questions tagged

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