Qbasicnews.com
February 27, 2020, 07:08:02 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: 1 [2] 3
  Print  
Author Topic: Need help please!!!!  (Read 8055 times)
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #15 on: August 20, 2004, 05:53:29 PM »

Don't you mean : instead of ;?
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
ak00ma
Ancient Guru
****
Posts: 669



« Reply #16 on: August 20, 2004, 06:12:05 PM »

Ouups....yeah,yeah....too much C#, too less QB... Wink
Logged

B 4 EVER
Moneo
Na_th_an
*****
Posts: 1971


« Reply #17 on: August 21, 2004, 09:28:52 PM »

WHITEY:
I like your solution, except the boolean attempt to "fix" invalid input numbers. It may work for negative numbers, but it won't work if you input a number 8 and above. What's wrong with:
Code:

if n < 1 or n > 7 then print "Sorry, invalid weekday number.":system


ZIRE:
I like your totally strightforward and straight-line code.

AK00MA:
Your array solution is nice, but:

1) I don't like the 0 to 6 range. It could be confusing to a user. In the US, since the week begins on Sunday, then 1 to 7 is Sunday to Saturday. Some other countries begin the week on Monday. In either case, the weekday numbers are 1 to 7.

2) Your use of the "n mod 8" is cute, but it doesn't solve the problem of invalid input numbers, it only converts it to something else. See my sample number validation code above.

IN GENERAL: If you post a solution for a newbie, give it your best shot, and most of all test it first. Some poor newbie may inherit some of your poorly written or buggy code.
*****
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #18 on: August 21, 2004, 10:04:19 PM »

Moneo: I didn't want to use IF =P I was going to do something with >7 but got lazy.
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Moneo
Na_th_an
*****
Posts: 1971


« Reply #19 on: August 21, 2004, 10:14:41 PM »

Ok Whitey, we'll forgive you this time. :wink:
Logged
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #20 on: August 21, 2004, 10:18:40 PM »

Quote from: "Moneo"
Ok Whitey, we'll forgive you this time. :wink:

Hey... What's that wink for?  :roll:
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
frostyservant
New Member

Posts: 12


« Reply #21 on: August 22, 2004, 05:51:07 AM »

Or...
I'm pretty n00bish myself, so forgive the  :barf:  style (especially the nasty goto loop... it's functional)...


Code:
TYPE daysofweek
name AS STRING * 9
END TYPE
DIM day AS daysofweek

' You would have to write the database entries beforehand,
' obviously...

OPEN "daysofweek.dat" FOR RANDOM AS #1 LEN = LEN(day)
recording:
INPUT "Number of day of week"; record
IF record < 1 OR record > 7 then goto recording
GET 1, record, day
PRINT "day.name"
CLOSE
END
Logged

hey say that if you play a Windows Install CD backwards, you can hear Satanic messages.  That's nothing, play it forwards and it installs Windows.
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #22 on: August 22, 2004, 08:44:06 AM »

Code:
DO
   INPUT "Number of day of week"; record
LOOP WHILE record < 1 OR record > 7


Wink
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
frostyservant
New Member

Posts: 12


« Reply #23 on: August 22, 2004, 09:49:26 AM »

Tongue

Yeah, I know, I know...
Logged

hey say that if you play a Windows Install CD backwards, you can hear Satanic messages.  That's nothing, play it forwards and it installs Windows.
Z!re
*/-\*
*****
Posts: 4599


« Reply #24 on: August 22, 2004, 10:41:24 AM »

Code:
INPUT "Number of day of week"; record
record=((record*2)\2) MOD 8


or

Code:
INPUT "Number of day of week"; record
record=ABS(record) MOD 8


lol....
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #25 on: August 22, 2004, 09:10:53 PM »

Quote from: "na_th_an"
Code:
DO
   INPUT "Number of day of week"; record
LOOP WHILE record < 1 OR record > 7


Wink


As usual, Nathan, a brilliant, stuctured solution. My problem is that I recognize the good solution, but I still code the old way with IFs.
*****
Logged
Moneo
Na_th_an
*****
Posts: 1971


« Reply #26 on: August 22, 2004, 09:19:24 PM »

Zire,

Your use of the MOD 8 is an attempt to force invalid input to a valid number. That's a wrong approach. If the user inputs an invalid number you have to inform him either with a message, or as Nathan does, by not accepting the input.

Besides, the MOD 8 will give you zero if the input is an 8 or other multiple of 8. This zero will certainly cause an error in the program or give garbage as a result.

Input has to be scrubbed, not forced to an acceptable value.

Do you get what I mean?
*****
Logged
Z!re
*/-\*
*****
Posts: 4599


« Reply #27 on: August 22, 2004, 11:27:38 PM »

Yup...

I'm mostly messing around Tongue

I still think my if's are the best solution, simple, functional, easy to understand.

Could even add a print after all the if's saying something like:
"You messed up!"

=)



BTW, it's Z!re...
Logged
ak00ma
Ancient Guru
****
Posts: 669



« Reply #28 on: August 23, 2004, 09:29:50 AM »

ok...I got it...

Nath's way:
Code:

DIM D$(1 TO 7)
D$(1) = "Sunday":D$(2) = "Monday":D$(3) = "Tuesday":D$(4) = "Wednesday":D$(5) = "Thursday"
D$(6) = "Friday":D$(7) = "Saturday"
DO
 INPUT "Please enter a number (between 1 and 7)", n
LOOP WHILE n < 1 AND n > 7
PRINT STR$(n) + "-->" + D$(n)
Logged

B 4 EVER
KiZ
__/--\__
*****
Posts: 2879


WWW
« Reply #29 on: August 23, 2004, 02:25:26 PM »

Gah! The ages of you being away from you shows ak00ma! You forgot the loop. =P

But i guess that was just a daft mistake..
Logged
Pages: 1 [2] 3
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!