Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to put the time and date into your program so that it runs regardless.
#11
[quote author=Smurfy link=topic=13132.msg153278#msg153278 date=1192745322]
[\quote]

The following code for determining a leap year is wrong.

   IF X MOD 400 = 0 OR (X MOD 100 = 0 OR X MOD 4 = 0) THEN

The code should be:
  ' If the year is evenly divisible by 4 and not divisible
  ' by 100, or if the year is evenly divisible by 400, then
  ' it's a leap year:

  IF (X MOD 4 = 0 AND X MOD 100 <> 0) OR (X MOD 400 = 0) THEN

Regards..... Moneo
Reply
#12
My advice: forget all about displaying the time continually. Why do you want to do that anyway? To be fancy? It is WAY to hard.

As you can see from my demo, I had to save and restore the cursor position. Now you introduce color. So I would have to save and restore that, too.

And any program that tries to do two things at once runs into the problem that INPUT will freeze the process. In other words, when you have an INPUT command, no other process can run until the user answers the question and presses Enter. Sorry, that's the way QBasic works. So you have to avoid INPUT and instead write your own INPUT routine using INKEY$ (no easy task!!!).

You are too junior a programmer to do all of that. Just leave all the gimmicks out and concentrate on solving the user's problem. I would not even waste time on COLOR commands - a waste of time.

Mac
Reply
#13
Well thank you first to MAC you were a big help but the reason I need it in my program is because thats what was asked of me by a friend, I'm better at QB than he is and he needs it for some college course hes taking on programming and hes decided to pay me $100 for it and I need all the money I can get for college.

Second thank you Moneo, I totally overlooked that.
Reply
#14
(10-19-2007, 07:40 AM)Smurfy link Wrote:pay me $100

Heh - What's my share?

Mac

DECLARE FUNCTION MyInput% (m$)
' Leapyear Calculator
ON TIMER(1) GOSUB UpdateTime
TIMER ON
DO
  CLS : LOCATE 3, 1
  TimeDisplayShowing = 0: WHILE TimeDisplayShowing = 0: WEND
  DO
    PRINT "Would you like to compute a range of years(1) or a single year(2): ";
    DO: q$ = INKEY$: LOOP WHILE q$ = ""
    IF q$ = CHR$(27) THEN SYSTEM
  LOOP WHILE q$ <> "1" AND q$ <> "2"
  PRINT q$
  IF VAL(q$) = 1 THEN GOSUB Range
  IF VAL(q$) = 2 THEN GOSUB SingleYear
  LOCATE 25, 1: PRINT "Would you like another run? Y/N: ";
  DO: R$ = UCASE$(INKEY$): LOOP WHILE R$ <> "Y" AND R$ <> "N"
LOOP WHILE R$ = "Y"
CLS
SYSTEM

Range:
DO
  F = MyInput("Enter the first year")
  L = MyInput("Enter the last year")
  IF F >= L THEN PRINT "Range out of order"
LOOP WHILE F >= L
FOR y = F TO L: GOSUB DoYear: NEXT y
RETURN

SingleYear:
y = MyInput("Enter a year")
GOSUB DoYear
RETURN

DoYear:
m = 2
IF y MOD 4 = 0 THEN
  m = 1
  IF y MOD 100 = 0 THEN
    m = 2
    IF y MOD 400 = 0 THEN m = 1
  END IF
END IF
IF m = 1 THEN
  TIMER OFF: COLOR 4, 0
  PRINT y; "is a leap year."
  COLOR 7, 0: TIMER ON
ELSE
  PRINT y; "is not a leap year."
END IF
RETURN

UpdateTime:
row = CSRLIN
col = POS(1)
LOCATE 1, 60: PRINT DATE$; " "; TIME$
LOCATE row, col, 1
TimeDisplayShowing = -1
RETURN

FUNCTION MyInput% (m$)
DO
  LOCATE , , 1: PRINT m$; ": ";
  start = LEN(m$) + 3
  w$ = ""
  DO
    DO: k$ = INKEY$: LOOP WHILE LEN(k$) <> 1
    SELECT CASE k$
    CASE "0" TO "9": IF LEN(w$) < 4 THEN w$ = w$ + k$: PRINT k$;
    CASE CHR$(13): PRINT
    CASE CHR$(27): SYSTEM
    CASE CHR$(8):
      LOCATE , start: PRINT SPACE$(4); : LOCATE , start
      IF LEN(w$) > 1 THEN
        w$ = LEFT$(w$, LEN(w$) - 1): PRINT w$;
      ELSE
        w$ = ""
      END IF
    END SELECT
  LOOP WHILE ASC(k$) <> 13
  PRINT
  IF VAL(w$) < 1583 THEN PRINT "Must be greater than 1582"
LOOP WHILE VAL(w$) < 1583
MyInput% = VAL(w$)
END FUNCTION

Reply
#15
Thank you so much you have been the biggest help possible!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)