Check for Multiple Digits techdude2007 Junior Member Posts: 2 Threads: 2 Joined: May 2008 05-13-2008, 05:45 AM I am trying to write a program that the user enters 4465 and the program checks to make sure that the same digits is not used twice in the number.Â  So in this case, the program would reject the number because there is 2 fours.Â  Any idea how to do this? Ralph Senior Member Posts: 544 Threads: 27 Joined: Jan 2005 05-13-2008, 10:35 AM (This post was last modified: 06-01-2008, 12:59 AM by Ralph.) This program does not allow one to enter any previously entered digit: Code:```REMÂ  Program omision error detected by Moneo and corrected by Ralph on June 1, 2008, as remarked on below CLS PRINT PRINT " This program allows entering a number with from 1 to 10 digits, but " PRINT " it only accepts entry of digits that have not been used before" PRINT PRINT " Type in your number, digit by digit.Â  When done, press Enter "; DIM n(20) AS INTEGER DO again: Â  k\$ = "": WHILE k\$ = "": k\$ = INKEY\$: WEND Â  IF k\$ = CHR\$(13) THEN EXIT DO 'new line, from Moneo's input Â  IF k\$ < "0" OR k\$ > "9" THEN GOTO again Â  i = i + 1 Â  n(i) = VAL(k\$) Â  FOR j = 1 TO i - 1 Â  Â  IF n(j) = n(i) THEN Â  Â  Â  i = i - 1 Â  Â  Â  GOTO again Â  Â  END IF Â  NEXT j Â  PRINT k\$; LOOP 'modified, due to Moneo's input system``` Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer. LPG Member Posts: 61 Threads: 11 Joined: Apr 2008 05-13-2008, 12:22 PM You could go like this: Code:```CLS PRINT "ENTER A NUMBER AND I WILL TELL YOU IF THERE ARE ANY REPEATS:"; LINE INPUT A\$ DIM NUMBERS(9) AS INTEGER FOR B = 1 TO LEN(A\$) IF NUMBERS(VAL(MID\$(A\$,B,1))) = 1 THEN REPEAT = 1 IF NUMBERS(VAL(MID\$(A\$,B,1))) = 0 THEN NUMBERS(VAL(MID\$(A\$,B,1))) = 1 NEXT B IF REPEAT = 1 THEN PRINT "THE NUMBER HAS A REPEAT" IF REPEAT = 0 THEN PRINT "THE NUMBER DOSN'T HAVE ANY REPEATS" SYSTEM``` WHILE RPG\$ <> "complete" : make up silly excuses :WEND Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 05-29-2008, 06:01 AM Here's a version with more error checking and complete reporting of duplicated digits. Regards..... Moneo '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' dim dup(0 to 9) input "Enter series of numbers "; n\$ if n\$="" then print "Error: null entry."ystem for x=1 to len(n\$) Â  Â  d\$=mid\$(n\$,x,1) Â  Â  if d\$<"0" or d\$>"9" then print "Invalid digit(s) found."ystem Â  Â  d=val(d\$) Â  Â  dup(d)=dup(d)+1 next x for x=0 to 9 Â  Â  if dup(x)>1 then gotdups=1:print "digit";x;"repeated";dup(x);"times." next x if gotdups=0 then print "No duplicate digits found." system Ralph Senior Member Posts: 544 Threads: 27 Joined: Jan 2005 05-30-2008, 08:37 PM LPG and Moneo: Seems as though techdude2007 has either not received any notification on any of our three posts, or that he has his answer(s) and believes that's the end of the story.Â  Nothing new, as I see this happen, now and then.Â  But, sometimes there is a valid reason for a long delay in answering...we'll see.Â  Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer. Dav Administrator Posts: 440 Threads: 65 Joined: Sep 2001 05-30-2008, 10:19 PM Well, here's another one ... Quote:Entry:Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  INPUT "Enter a number: ", numÂ  Â  Â  ' Get a number entry only Â  num\$ = STR\$(num)Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  ' Convert it to a string Â  FOR s = 1 TO LEN(num\$) - 1Â  Â  Â  Â  Â  ' Step through string. Â  Â  h\$ = MID\$(num\$, s, 1)Â  Â  Â  Â  Â  Â  Â  Â  ' Get a nibble here... Â  Â  t\$ = MID\$(num\$, s + 1, 1)Â  Â  Â  Â  Â  ' ...and a nibble there. Â  Â  IF h\$ = t\$ THENÂ  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  ' If both are the same, Â  Â  Â  PRINT "Duplicate! Re-enter!"Â  Â  ' then say so ... Â  Â  Â  GOTO EntryÂ  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  ' ...and go back. Â  Â  END IF Â  NEXT Â  PRINT "No duplicates found."Â  Â  Â  Â  ' If you make it here, all OK. Visit Dav's Qbasic Site Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 05-31-2008, 06:39 AM Dav, I think your solution assumes that the duplicate numbers are adjacent, like 4465. But, what if they are not adjacent, like 4654? Regards..... Moneo Dav Administrator Posts: 440 Threads: 65 Joined: Sep 2001 05-31-2008, 08:37 AM Oops...I read the thread too quickly and failed to fully see what was asked for. My apologies to all.Â  - Dav Visit Dav's Qbasic Site Ralph Senior Member Posts: 544 Threads: 27 Joined: Jan 2005 05-31-2008, 08:48 AM Hi, Moneo!Â  What's wrong with my proposed solution? Ralph, using QuickBASIC 4.5 and Windows XP Home Edition and Service Pack 2, with HP LaserJet 4L printer. Moneo Posting Freak Posts: 1,956 Threads: 65 Joined: Jun 2003 06-01-2008, 12:28 AM Ralph, The way you have it just goes into an endless loop. What happens is that the chr\$(13) is caught by the test if less than "0" or greater than "9", and thus the chr\$(13) is never seen later by the LOOP UNTIL. If you put the test for chr\$(13) right after the INKEY line, then it works. You can relace the LOOP UNTIL with a plain LOOP. Regards..... Moneo « Next Oldest | Next Newest »