PRINT USING help please!!!!

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
elmagic
Newbie
Posts:1
Joined:Mon Oct 06, 2008 10:13 pm
Location:home
PRINT USING help please!!!!

Post by elmagic » Mon Oct 06, 2008 10:21 pm

Ok, so my programming teacher gave my class a program that we had to write, and then told us not to do it. But, since I'm stubborn and refuse to give up once I've started something, I kept trying. Eventually, by teaching myself how to use functions and keywords he never taught us, I came up with what is below. I just want to know if this is the best way to do it with my limited beginner's knowledge.

The criteria for the program is as follows:

2.7) Ask the user to enter 3 numbers from 1000 - 9999. Have the computer ROUND them off to the nearest ten, hundred, and thousand. Have your OUTPUT at columns 1, 21, 41, 61.

NUMBER TEN HUNDRED THOUSAND
----- --- ---- -----



He also said that we HAVE to use PRINT USING.

This is what I came up with:

CLS

INPUT "Enter 3 numbers from 1000 - 9999: ", x, y, z
PRINT
PRINT "NUMBER"; TAB(21); "TEN"; TAB(41); "HUNDRED"; TAB(61); "THOUSAND"
PRINT

PRINT x; TAB(21); USING "##"; (x * (1 / 100));
PRINT TAB(41); USING "###"; (x * (1 / 10));
PRINT TAB(61); x
PRINT y; TAB(21); USING "##"; (y * (1 / 100));
PRINT TAB(41); USING "###"; (y * (1 / 10));
PRINT TAB(61); y
PRINT z; TAB(21); USING "##"; (z * (1 / 100));
PRINT TAB(41); USING "###"; (z * (1 / 10));
PRINT TAB(61); z

--------------------------------------------------------------------------------

How is it?

Thanks a million,

elmagic
I don't even know where I am right now....

User avatar
DDastardly71
Jr. Member
Posts:15
Joined:Sun Jan 20, 2008 11:25 pm

Print Using

Post by DDastardly71 » Wed Oct 15, 2008 5:20 am

The easiest way of using Print Using is to assign your layout to a string variable and re-use that over and over again.

This sample below aligns the heading to the specified columns you provided and the Detail$ variable containts the numeric layout. This is the easy way, no computing of the column position, just move the '#' digit position using your space bar.

You may want to review your formulas...what happen if the user enter '52'?

Hope it helps...


NOTE: I used the '^' character in place for the space since it won't allow me to insert spaces. Just delete is when you run the program.

DEFINT A-Z

Main:
Heading$ = "NUMBER^^^^^^^^^^^^^^TEN^^^^^^^^^^^^^^^^^HUNDRED^^^^^^^^^^^^^THOUSAND"
Detail$ = "#,###^^^^^^^^^^^^^^^^##^^^^^^^^^^^^^^^^^^^###^^^^^^^^^^^^^^^^^#,###"

CLS

INPUT "Enter 3 numbers from 1000 - 9999: ", x, y, z

PRINT Heading$
PRINT USING Detail$; x; (x * (1 / 100)); (x * (1 / 10)); x
PRINT USING Detail$; y; (y * (1 / 100)); (y * (1 / 10)); y
PRINT USING Detail$; z; (z * (1 / 100)); (z * (1 / 10)); z
END

Post Reply