QBASIC Chapter 11 - Output Formatting, Part 2 Chapter Eleven Output Formatting, Part Two Keyword: PRINT USING As usual, here are the answers to the problems at the end of the previous chapter. This is the program that we came up with for the coin flipping problem. Of course, it won't be exactly like yours, but it will probably be similar. To find out if yours is correct, run both yours and ours, and see if they operate in a similar manner. The location of the displayed output on the screen may be different, too.
Anyway, here is our program: CLS RANDOMIZE TIMER / 3 LOCATE 5, 19 PRINT 'HEADS' LOCATE 5, 39 PRINT 'TAILS' LOCATE 6, 20 PRINT HEADS LOCATE 6, 40 PRINT TAILS FOR COIN = 1 TO 2500 LET FLIP = INT(2. RND) + 1 IF FLIP = 1 THEN GOTO ISHEADS LET TAILS = TAILS + 1 LOCATE 6, 40 PRINT TAILS GOTO NEXTFLIP ISHEADS: LET HEADS = HEADS + 1 LOCATE 6, 20 PRINT HEADS NEXTFLIP: NEXT COIN END When we came up with the problem, we hadn't yet developed the program for the solution, and discovered that it would have saved four lines to not print out the zeros initially. Here is the program to draw the diagonal line of asterisks: CLS FOR STAR=1 TO 22 LOCATE STAR, STAR PRINT'.' NEXT STAR END To modify this program to get the next one, simply change line 3 to read: LOCATE STAR, 2. STAR In this chapter, we will reintroduce the PRINT command, but this time it has a powerful extension to it. In fact, it does so much that we won't even discuss all of its features here. That's because some of them have to do with string variables, which we will introduce later on.
Let's get right into it. Here is an example program for you to type in: CLS FOR NUM = 1 TO 20000 LOCATE 5,10 PRINT NUM NEXT NUM END Now run the program, and notice how it behaves.
If you didn't catch it, run it a few more times. Do you notice that as the number grows larger (has more digits) that it 'grows' to the right? This means that the numbers are 'left justified'. Run it again, and notice especially at the start that the fastest changing number moves to the right by one position as the number grows larger. Now change line 4 to read: PRINT USING '#####';NUM Now run the program a few more times. Notice that now the number 'grows' to the left? In other words, the ones position does not shift over as the number becomes larger.
This is called 'right justified', and is useful for columns of numbers, because the digits will line up. What do those number signs do, and why are there five of them in the PRINT USING command? The number sign represents a digit in the output format. In other words, the USING part of the PRINT command tells the computer just how to print out our numeric variable.
Since we have 5 #'s, we are telling the computer to reserve 5 spaces to print out digits. If we needed to print a larger number, we would need to add another number sign. What happens if there are more digits than number signs? Let's find out. Change line 4 to: PRINT USING '####';NUM Now run the program.
You won't notice a difference until the number 10000 is printed. What do you get? That's right, it prints out%10000.
That percent sign is QBASIC's way of showing us that we have a formatting error. It does not stop the program in its tracks, though. To fix that little formatting problem, simply add another number sign or two. It sounds simple so far, but let's try something else. Change the program to (Changes are in green): CLS FOR NUM = 1 TO 2000 STEP.1 LOCATE 5, 10 PRINT USING '####'; NUM NEXT NUM END Now run the program.
Does it do what you expected? We expected it to count from 1 to 2000, incrementing by 0.1 each time, but all we get are whole numbers! We did not specify a decimal point in our format, so QBASIC assumes that it goes at the end. How do we fix that?
Change line 4 to: PRINT USING '####.#';NUM Now run the program again. Much better, wouldn't you say? What was happening to the number when the decimal point was being cut off?
Let's find out. Type this in the immediate window: PRINT USING '#';1.4 Do you see what the answer is?
The computer spits back a '1'. I guess we could expect that. Now try this: PRINT USING '#';1.5 AH-HA!! Now the computer gave us a '2'.
This thing is pretty smart! It knows how to round off the answers! Let's try something else. Change the program to: CLS FOR NUM = 900 TO -900 STEP -1 LOCATE 5,10 PRINT USING '###'; NUM NEXT NUM END and run the program. Do you notice our little formatting error symbol?
Rosina Surovi Khan et al. / (IJCSE) International Journal on Computer Science and Engineering Vol. 08, 2010, 2616-2621 Design of a Hospital-Based Database. Database design for hospital pdf. Free PDF ebooks (user's guide, manuals, sheets) about Database design for hospital management system ready for download. “Designing and Interfacing a Hospital-Based Database System ”. 2.4 Relational Database Design. As our thesis paper is on Designing and Interfacing a.
It's because we specified 3 digit positions. It works fine for the positive numbers, but when we get to the negative numbers, we must specify a space for the minus sign. Change line 4 to: PRINT USING '####';NUM Now RUN the program again. Ah, that's better! But suppose we are doing some kind of engineering work, and we would like the sign to be printed even for a positive answer.
What do we do then? Well, one of the specifiers for our format is the plus sign, +. To see it in action, change line 4 to: PRINT USING '+###';NUM Now run it and watch closely. Did you notice that the program printed a plus sign for the positive numbers, and a minus sign for the negative numbers?
If you missed them, run the program a few more times. The numbers fly by fast, so watch closely.
Change the STEP size to -0.1 or -0.01 to slow it down if you have to. Let's switch to accounting type problems. Suppose we have some huge numbers we want to print out.
Let's start a new program to help us with these next few examples: CLS LET NUM = 1 MORE: LOCATE 5, 10 PRINT USING '#######'; NUM LET NUM = NUM. 1.01 IF NUM.
Best Answer: 'Write a program in Qbasic to display the following pattern with Nested For Loop? '1 '0 1 '0 1 0 '1 0 1 0 '1 0 1 0 1 this question is spam.
I have seen it again and again. I don't know what the possible purpose of this code torture. Maybe it's 'cool' to kids in the USA, but in the USA for real programmers it only used to be 'cool' to do 30 years ago when microcomputers were first invented and people were looking for ways to make use of them and tinker with them. Only kids today pull tricks like that. Employers want something more serious in code. I can do it, but the code is - wasteful of my time and resources - wasteful of cpu cycles (inefficient way of doing things to use a nested for loop) - I can't see a use for this in production code - a challenge - that's it's only redeeming quality - you should be able to figure this out.
Print Pattern Blog
Dim str as string,x as integer,y as integer str=' for x=1 to 2 for y=1 to 1 str = str & string$(y) print str next y if (1=x) then for y=0 to 0 str = string$(y) & str print str next y for y=0 to 0 str = str & string$(y) print str next y for y = 1 to 1 str = string$(y) & str print str next y end if next x 'or for x=1 to 1 for y=1 to 1 str = str & string$(y) print str next y for y=0 to 0 str = string$(y) & str print str next y for y=0 to 0 str = str & string$(y) print str next y for y = 1 to 1 str = string$(y) & str print str next y for y=1 to 1 str = str & string$(y) print str next y next x. Once you bypass to take the try, in the event that they ask a question like this, how are you going to answer in case you won't be in a position to bypass on line and ask? Besides, you're actually not asking a question - you're stressful that we 'Write a application. ' (i don't respond nicely to demands!) Now then, in case you have been to coach us what you have executed to date, and ask for counsel, that could desire to be yet another element altogether. I like to help human beings. I refuse to do the artwork FOR them, yet i like to help them.
There's a distinction you recognize. Solid luck on your try, and characteristic exciting programming. Tell us some more. Upload in progress. Upload failed.
Please upload a file larger than 100 x 100 pixels. We are experiencing some problems, please try again. You can only upload files of type PNG, JPG or JPEG. You can only upload files of type 3GP, 3GPP, MP4, MOV, AVI, MPG, MPEG or RM.
Qbasic Free Download
You can only upload photos smaller than 5 MB. You can only upload videos smaller than 600 MB. You can only upload a photo (png, jpg, jpeg) or video (3gp, 3gpp, mp4, mov, avi, mpg, mpeg, rm). You can only upload a photo or video.
Video should be smaller than 600 MB/5 minutes. Photo should be smaller than 5 MB.
Follow Blog via Email Enter your email address to follow this blog and receive notifications of new posts by email. Join 33 other followers. Hack Community - The Best Ethical Hacking Forums - Profile of PsychoCoder via @. Hack Community - The Best Ethical Hacking Forums via @. Hack Community - The Best Ethical Hacking Forums via @.
Qbasic Programming Language Download
Hack Community - The Best Ethical Hacking Forums via @. Hack Community - The Best Ethical Hacking Forums via @. Create Your Logo Free: crete. Create Your Logo Free:. Welcome to Computer Geeks. Just updated my website its beetterer.
Just updated my website Blogs I Follow. Blog Stats. 218,230 hits Cloud Tags.
. Tell us some more.
Upload in progress. Upload failed. Please upload a file larger than 100 x 100 pixels. We are experiencing some problems, please try again. You can only upload files of type PNG, JPG or JPEG. You can only upload files of type 3GP, 3GPP, MP4, MOV, AVI, MPG, MPEG or RM.
You can only upload photos smaller than 5 MB. You can only upload videos smaller than 600 MB. You can only upload a photo (png, jpg, jpeg) or video (3gp, 3gpp, mp4, mov, avi, mpg, mpeg, rm). You can only upload a photo or video. Video should be smaller than 600 MB/5 minutes. Photo should be smaller than 5 MB.