Problem involving 3 digit numbers

  • Thread starter Thread starter issacnewton
  • Start date Start date
  • Tags Tags
    Numbers
Click For Summary
SUMMARY

The discussion revolves around a program designed to generate a random three-digit number between 100 and 999, where users guess the number for prizes based on the accuracy of their guesses. The logic for awarding prizes is clearly defined: an exact match yields the highest prize, while matches of individual digits result in progressively lower prizes. The user, IssacNewton, faced challenges implementing the logic for cases where one or two digits match, but received a solution from Scott involving the use of an array to store digits and a nested loop to count matches.

PREREQUISITES
  • Understanding of basic programming concepts, particularly conditional statements.
  • Familiarity with arrays and loops in programming.
  • Knowledge of random number generation techniques.
  • Experience with prize allocation logic based on user input.
NEXT STEPS
  • Implement and test random number generation in Python using the random module.
  • Learn about array manipulation and searching algorithms in programming.
  • Explore advanced conditional logic to handle multiple matching scenarios.
  • Research user input validation techniques to enhance the guessing game experience.
USEFUL FOR

Programmers, game developers, and educators looking to implement interactive guessing games or improve their understanding of logic and array manipulation in programming.

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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 46 ·
2
Replies
46
Views
7K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 17 ·
Replies
17
Views
2K
Replies
25
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 6 ·
Replies
6
Views
1K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 4 ·
Replies
4
Views
3K