Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Problem involving 3 digit numbers

  1. Jan 27, 2014 #1
    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
     
  2. jcsd
  3. Jan 27, 2014 #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;
    }
    }
    }
     
  4. Jan 27, 2014 #3
    thanks Scott.... makes sense
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Problem involving 3 digit numbers
  1. Number of digits in n! (Replies: 8)

  2. Number of digit (Replies: 2)

Loading...