Problem involving 3 digit numbers

  • Thread starter issacnewton
  • Start date
  • Tags
    Numbers
In summary, the program generates a random three-digit number and prompts the user to guess the number. The user can win different prizes depending on the number of digits they match with the original number. The program uses if-else statements and an array to count the number of correct digits in the guess. There may be issues with logic in cases where the guess has two or one correct digits.
  • #1
issacnewton
1,000
29
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
  • #2
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;
}
}
}
 
  • #3
thanks Scott... makes sense
 

What is a 3 digit number?

A 3 digit number is a number that has three digits, or places, separated by a comma. For example, 345 is a 3 digit number, with 3 being the hundreds place, 4 being the tens place, and 5 being the ones place.

What is the largest 3 digit number?

The largest 3 digit number is 999. This is because the first digit (hundreds place) can only go up to 9, and the other two digits (tens and ones place) can also only go up to 9.

What is the smallest 3 digit number?

The smallest 3 digit number is 100. This is because the first digit (hundreds place) cannot be 0, and the other two digits (tens and ones place) can go up to 9.

What is the value of the digit in the ones place?

The digit in the ones place is the number that represents the singles or units. For example, in the number 356, the digit in the ones place is 6.

How many 3 digit numbers are there?

There are 900 3 digit numbers. This can be found by multiplying 9 (the number of options for the hundreds place) by 10 (the number of options for the tens place) by 10 (the number of options for the ones place).

Similar threads

  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
2
Replies
46
Views
4K
  • Programming and Computer Science
Replies
1
Views
937
  • Programming and Computer Science
Replies
8
Views
1K
  • Programming and Computer Science
Replies
17
Views
1K
Replies
25
Views
3K
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
4K
  • Set Theory, Logic, Probability, Statistics
Replies
8
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
3K
Back
Top