Problem involving 3 digit numbers

  • Thread starter Thread starter issacnewton
  • Start date Start date
  • Tags Tags
    Numbers
AI Thread Summary
The discussion revolves around creating a number-guessing game where users guess a randomly generated three-digit number between 100 and 999. The program awards prizes based on the accuracy of the user's guess: an exact match yields the highest prize, while matching all digits earns a lower prize, and so on, down to no prize for incorrect guesses. The user, facing challenges with the logic for counting correct digits, seeks advice on implementing this using an if-else structure. A suggested solution involves storing the digits in an array and using nested loops to count matches, ensuring that once a digit is matched, it is marked to prevent double counting. This approach clarifies how to effectively manage the logic for varying levels of correctness in the guesses.
issacnewton
Messages
1,035
Reaction score
37
Hello

I am writing a program where program will randomly generate a three digit number from 100 to 999 and then user will be asked to guess that number. If the number is matched exactly, then the highest prize is given to the user, if all digits in a guess are also in the original number, next highest prize will be given to the user. If two digits from guess are correct, then the next prize . If one digit from the guess is correct, then the next one. Finally no prize for the guess where no digits match.
I tried to use if-else construct for this. I am able to get the first two correct. But I am having problems with logic where guess might have two of its digits correct and where guess might have only single digit correct. Any specific ideas ?

thanks
IssacNewton
 
Technology news on Phys.org
Store the digits in an array. Loop through the array and count the matches.
nCount=0;
for(nR=0;nR<3;nR++) naTemp[nR] = naRandom[nR]
for(nG=0;nG<3;nG++) {
nGD = naGD[nG];
for(nR=0;nR<3;nR++) {
if(nDG==naTemp[nR]) {
nCount++;
naTemp[nR] = -1;
break;
}
}
}
 
thanks Scott... makes sense
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...

Similar threads

Back
Top