Check for Multiple Digits - Printable Version +- Qbasicnews.com (http://qbasicnews.com/newforum) +-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html) +--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html) +--- Thread: Check for Multiple Digits (/thread-10117.html) Pages:
1
2
|
Check for Multiple Digits - techdude2007 - 05-13-2008 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? Re: Check for Multiple Digits - Ralph - 05-13-2008 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 Re: Check for Multiple Digits - LPG - 05-13-2008 You could go like this: Code: CLS Re: Check for Multiple Digits - Moneo - 05-29-2008 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 Re: Check for Multiple Digits - Ralph - 05-30-2008 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. Re: Check for Multiple Digits - Dav - 05-30-2008 Well, here's another one ... Quote:Entry:               Re: Check for Multiple Digits - Moneo - 05-31-2008 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 Re: Check for Multiple Digits - Dav - 05-31-2008 Oops...I read the thread too quickly and failed to fully see what was asked for. My apologies to all. - Dav Re: Check for Multiple Digits - Ralph - 05-31-2008 Hi, Moneo! What's wrong with my proposed solution? Re: Check for Multiple Digits - Moneo - 06-01-2008 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 |