Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
So I've been using QBASIC64 today... for old school's sake.
I was wondering:
a) What is the most complex QBASIC code you have ever written was
and
b) What is the most useful code you have written
(examples would be nice but not imperative ^_^ - and this is Community Wiki and just for fun)
GOTO used to be so easy those days :-)
Although I never used QBasic (I managed to skip the generation of machines that had it) I did write a Z80 assembler in its predecessor, GWBasic, together with support code for some hardware to transfer the resulting machine code to my test platform. It most certainly qualified as complex, as well as being very messy and slow, but that's because I didn't know better (having not taken any data structures and algorithms classes at that point).
Most complex: Huffman coder using a string to store the tree. I don't think i got it working.
Most useful: Palace chat maze editor/generator.
I never really got so far with QBasic.
This would be because I'm not an old programmer.
Most I ever did, (fitting both A) and B) )
was make a program the read a number from keyboard,
and then calculated 10% of it, pringitng that to screen.
This must have been in 2000, as 10% gst was being introduced in australia.
That makes me 9 years old.
I remember spending like 6 months looking for a computer with QBasic on it.
Fond memories, of the, not so, distant past
Most Useful, and probably most complex: I wrote a quizzer program in QBasic that had mouse support, graphical buttons you could click, etc. It also used a generic file format so you could write new questions and load them in if you wanted to. The code is online if you are interested, although sadly the associated image / data / etc files are lost to time:
http://code.google.com/p/justinethier/source/browse/trunk/qbasic_quizzer/project.bas
answer for both a and b: a program where the user would enter the string name and fret number on a guitar and the program would output which note the fret is. BTW, I love qbasic because its simplicity makes it fun!
QBasic was my first experience with programming. I was nine-years old (fourth grade) and we had a 386DX with MS-DOS and Windows 3.1.
I remember having fun hacking the code for Nibbler and Gorillas changing colors and constants and such.
So the most useful and complex program I made was a menu driven application which quizzed the user on math problems: there were ascending numeric levels of difficulty the user could choose from and I remember literally hardcoding 100 arithmetic problems checking the users response and telling them whether they got it wrong or not.
Not sure if I still have that code laying around, I think I might, I'll check tonight and post if I find it!
...alright! I found some stuff. This snippet is part of a file named "TEST1.BAS" and looks like an early version of the program described above. I believe I had a more complete version but it was lost when our hard drive crashed and we weren't able to recover all files.
CLS
PRINT
PRINT " menu"
PRINT "--------------"
PRINT "1. level 1"
PRINT "2. level 2"
PRINT "3. level 3"
PRINT "4. level 4"
PRINT "5. level 5"
PRINT "6. level 6"
PRINT "7. level 7"
PRINT "8. level 8"
PRINT "9. level 9"
PRINT "10. level 10"
PRINT "11. OTHER"
PRINT
INPUT "Your selection: ", choice%
PRINT
IF choice% = 1 THEN
CLS
DO
INPUT "what is 4 + 4 ? ", num
LOOP UNTIL num = 8
PRINT
PRINT "correct"
DO
INPUT "what is 8 - 6 ? ", num
LOOP UNTIL num = 2
PRINT
PRINT "correct"
DO
INPUT "what is 8 + 7 ? ", num
LOOP UNTIL num = 15
PRINT
PRINT "correct"
DO
INPUT "what is 9 - 4 ? ", num
LOOP UNTIL num = 5
PRINT
PRINT "correct"
DO
INPUT "what is 6 + 5 ? ", num
LOOP UNTIL num = 11
PRINT
PRINT "correct"
END IF
IF choice% = 2 THEN
CLS
DO
INPUT "what is 11 + 6 ? ", num
LOOP UNTIL num = 17
PRINT
PRINT "correct"
DO
INPUT "what is 21 - 5 ? ", num
LOOP UNTIL num = 16
PRINT
PRINT "correct"
DO
INPUT "what is 2 * 2 ? ", num
LOOP UNTIL num = 4
PRINT
PRINT "correct"
DO
INPUT "what is 14 + 8 ? ", num
LOOP UNTIL num = 22
PRINT
PRINT "correct"
DO
INPUT "what is 17 - 5 ? ", num
LOOP UNTIL num = 12
PRINT
PRINT "correct"
END IF
IF choice% = 3 THEN
END IF
IF choice% = 4 THEN
END IF
IF choice% = 5 THEN
END IF
IF choice% = 6 THEN
END IF
IF choice% = 7 THEN
END IF
IF choice% = 8 THEN
END IF
IF choice% = 9 THEN
END IF
IF choice% = 10 THEN
END IF
Related
I'm completely lost on some homework. The assignment is to use a while loop and prompt the user to enter 5 numbers. My current code looks like the following:
$x = 1
do
{
Write-Host 'Enter 5 numbers'
$x++
} while ($x -eq 5)
Seems like issue is somewhere in here ($x -eq "5"). I want PowerShell just to prompt the user for 5 random numbers then get the sum of those numbers.
A homework assignment. 8^}
Oh well... Here is one way to do this.
Yet, taking your original post and what you show in your comment. Your issue is, you are not capturing anything to sum up, nor are you using a counter to meet you entry limit.
Clear-Host
# Initial variables
$ResponseCount = 0
$Total = 0
do {
# Get a user response
$response = Read-Host "Enter 5 numbers"
# increment response counts
$ResponseCount ++
# capture and sum the entered numbers
$Total += $response
}
until ($ResponseCount -eq "5")
"`nYou have completed the required 5 entries"
"The sum of the entered numbers is: $Total"
Enter 5 numbers: 10
Enter 5 numbers: 20
Enter 5 numbers: 30
Enter 5 numbers: 40
Enter 5 numbers: 50
You have completed the required 5 entries
The sum of the entered numbers is: 150
You're correct that the issue is your condition for the loop. Currently you're telling PowerShell to run the loop while $x is exactly five. If you want your loop to properly work you will have to change the condition. You can check the PowerShell help for about_Comparison_Operators to get an idea about the operators that are available.
The other thing you need to do is read the actual values and save whatever the user enters to build the sum. There are quite a few approaches to this and the other answer has a solution for that. Also consider using more expressive variable names to make it easier for someone else to follow your code (though that's not so much an issue for this short example).
This question already has answers here:
What's the best way to get the last N elements of a Perl array?
(6 answers)
Closed 7 years ago.
If i have an array that I've used to create 50 random numbers, I then sort them numerically. Now lets say I wanted to print out the 10 biggest number (elements 40 to 50) I could say:
print($array[40]) print($array[41]) print($array[42]) etc etc.
But is there a neater way to it? Hope I'm making myself clear.
Cheers
You could loop over the indexes.
say $array[$_] for 40..49;
Offsets from the end make more sense here.
say $array[$_] for -10..-1;
You could also use an array slice.
say for #array[-10..-1];
To print them on one line, you can use join.
say join ', ', #array[-10..-1];
Try this :
print join ',',#array[-10..-1] ,"\n";
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
How to check if one floating point number is bigger than another number in Perl?
i.e: 100.4 > 90
I tried to work with use POSIX, rounding the 100.4 to 101.0 and converting both of them with int, but Perl still thinks that my 100.4 is smaller than my 90.
Edit: The bug was somewhere else. The privious code returned me sometimes true and sometimes false.
No, Perl doesn't 'think' that, and that's easy to check:
print 100.4 > 90 ? 'Greater' : 'Lesser'; # Greater
My (wild) guess is that you've tried to sort an array of floats, and got 100.4 standing before 90. For example, like this:
my #floats = (100.4, 50, 9);
print $_, "\n" for sort #floats;
# 100.4
# 50
# 9
The catch is that by default Perl uses string comparison in sort. So both 100.4 and 90 are cast to string first, and '100.4' is indeed lesser than '9', because '1' is lesser than '9' (strings are compared char-by-char).
The solution is simple: override the sorting routine when dealing with numbers.
print $_, "\n" for sort { $a <=> $b } #floats;
# 9
# 50
# 100.4
I've searched for a while, but i couldn't find anything that could help me.
Let's say the first cell(or value, etc.) equals 165. How do i print "165"?
My idea was to cut the number into seperate pieces: 1,6 and 5. It would than be no problem to print them.
Note: I don't just want to print "165". I want to print the value the first cell has. No matter if it's 165, 255, 0, 1 or anything else.
use a famous modulo procedure ( http://esolangs.org/wiki/brainfuck_algorithms will help you)
>+++++++++++[-<+++++++++++++++>] # initialize 165 at first cell
>++++++++++<<[->+>-[>+>>]>[+[-<+>]>+>>]<<<<<<]>>[-]>>>++++++++++<[->-[>+>>]>[+[-
<+>]>+>>]<<<<<]>[-]>>[>++++++[-<++++++++>]<.<<+>+>[-]]<[<[->-<]++++++[->++++++++
<]>.[-]]<<++++++[-<++++++++>]<.[-]<<[-<+>]
I have created a simple language that compiles to brainfuck which can be found here: http://code.google.com/p/brainfuck-compiler. There is a compiler for the language implemented in java.
I use the following function in that language to output a number. Maybe you can analyze the generated code and see if anything can be of use to you from it. One word of warning though, it does generate a bit of redundant copying around of cells (never got around to optimizing this). Anyway here's an example program and the BF code it generates. (note that indentations MUST be tabs in my language)
declare n, 165
declare digits
while n
push n % 10
digits = digits + 1
n = n / 10
if digits
while digits
out pop + 48
digits = digits - 1
else
outs "0"
And here is the generated code for that:
>>>>>>>>>+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
++++++++++++++[<+>-]<[>>+>+<<<-]>>>[<<<+>>>-]<[[-]<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-
]++++++++++<[>>+>+<<<-]>>>[<<<+>>>-]<[>+<-]>[<<[>>>+>+<<<<-]>>>>[<<<<+>>>>-]<[>+
<<-[>>[-]>+<<<-]>>>[<<<+>>>-]<[<-[<<->>[-]]+>-]<-]<<+>]<[>>+<<-]>>[<<<[>+>+<<-]>
>[<<+>>-]>-]<<[<<->>-]<[-]<[>>>>>>>>+<<<<<<<<-]>>>>>>>>>[>>]+[<<]>[>[>>]<+<[<<]>
-]<<<<<<<<<<[>>+>+<<<-]>>>[<<<+>>>-]+[<+>-]<<<[-]>>[<<+>>-]<<<[>>>+>+<<<<-]>>>>[
<<<<+>>>>-]++++++++++<[>>+<<-]>>[<[>>+>+<<<-]>>>[<<<+>>>-]<[>+<<-[>>[-]>+<<<-]>>
>[<<<+>>>-]<[<-[<<<->>>[-]]+>-]<-]<<<+>>]<[-]<<<<[-]>>>[<<<+>>>-]<<<[>>>+>+<<<<-
]>>>>[<<<<+>>>>-]<[<+>-]<]<[>+>+<<-]>>[<<+>>-]<[>+<[-]]+>[<[-]<[>>>+>+<<<<-]>>>>
[<<<<+>>>>-]<[[-]>>>>>>>>[>>]<[<[<<]<<<<<+>>>>>>>[>>]<-]<-<<[<<]<<<<<>++++++++++
++++++++++++++++++++++++++++++++++++++[<+>-]<.[-]<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+
>>>>>-]+[<->-]<<<<<[-]>>>>[<<<<+>>>>-]<<<<[>>>>+>+<<<<<-]>>>>>[<<<<<+>>>>>-]<[<+
>-]<]<[-]]<[>>++++++[<++++++++>-]<.[-]<[-]]<[-]<[-]>>>>>>>>>>>>[>[-]>]<<[-<<]<<<
<<<<<<<<<<<<<<[-]<[-]
I need a Perl script which takes numbers as input example 222
and it should output as two hundred twenty two.
Use Lingua::EN::Numbers - turn "407" into "four hundred and seven", etc.
use Lingua::EN::Numbers qw(num2en num2en_ordinal);
my $x = 234;
my $y = 54;
print "You have ", num2en($x), " things to do today!\n";
print "You will stop caring after the ", num2en_ordinal($y), ".\n";
prints:
You have two hundred and thirty-four things to do today!
You will stop caring after the fifty-fourth.
If you read the documentation of the module then you will find that the module also support the following things like,
It can handle integers like "12" or "-3" and real numbers like "53.19".
It also understands exponential notation -- it turns "4E9" into "four times ten to the ninth.
It turns "INF", "-INF", "NaN" into "infinity", "negative infinity", and "not a number", respectively.
Number::Spell can help you:
use Number::Spell;
my $str = spell_number(222);
Here is one:
Number to Word Converter - Perl Engineering Project Download
Description: This basically converts a
number into words. It can only convert
numbers less than or equal of
novemdecillion quantity. It has a
complete input validation process.