QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: MelissaB, kgudger, Ray Trent, Moderators

QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT

Postby Cardcounter » Sun Oct 21, 2007 6:11 pm

I AM WORKING ON THE CARD COUNTING PROJECT SUGGESTED ON YOUR SITE. I AM LEARNING QBASIC IN ORDER TO DO THE PROGRAMMING FOR THE PROJECT. I HAVE PROGRAMMED THE RANDOM SORTING OF THE DECK OF CARDS. I WOULD LIKE TO PUT THE INFORMATION IN A FILE IN ORDER TO MAKE SURE THAT I AM ONLY PULLING 4 CARDS OF EACH NUMBER (4 2'S; 4 10'S, ETC). I CAN MAKE IT PRINT ON THE SCREEN, BUT I NEED TO GET THE INFORMATION INTO A FILE AND MY PROGRAM IS NOT WORKING. CAN YOU HELP ME? THIS IS WHAT I HAVE SO FAR.

REM: THE FOLLOWING VALUES ARE USED TO COUNT THE NUMBER OF TIMES A SPECIFIC CARD IS PLAYED WITH A MAX OF 4 TIMES EACH.
REM: A=2'S B=3'S.....0= 13/KINGS AND Q=14/ACES

CLS


A = 0
B = 0
C = 0
D = 0
E = 0
F = 0
G = 0
H = 0
I = 0
J = 0
k = 0
M = O
Q = 0
S = 0

OPEN "CardResults.txt" FOR INPUT AS #1



FOR X = 1 TO 52

99 :
RANDOMIZE TIMER
DO
R = INT(RND * 13 + 2)
IF R = 2 THEN A = A + 1: IF A = 1 OR A = 2 OR A = 3 OR A = 4 THEN EXIT DO ELSE GOTO 99
IF R = 3 THEN B = B + 1: IF B = 1 OR B = 2 OR B = 3 OR B = 4 THEN EXIT DO ELSE GOTO 99
IF R = 4 THEN C = C + 1: IF C = 1 OR C = 2 OR C = 3 OR C = 4 THEN EXIT DO ELSE GOTO 99
IF R = 5 THEN D = D + 1: IF D = 1 OR D = 2 OR D = 3 OR D = 4 THEN EXIT DO ELSE GOTO 99
IF R = 6 THEN E = E + 1: IF E = 1 OR E = 2 OR E = 3 OR E = 4 THEN EXIT DO ELSE GOTO 99
IF R = 7 THEN F = F + 1: IF F = 1 OR F = 2 OR F = 3 OR F = 4 THEN EXIT DO ELSE GOTO 99
IF R = 8 THEN G = G + 1: IF G = 1 OR G = 2 OR G = 3 OR G = 4 THEN EXIT DO ELSE GOTO 99
IF R = 9 THEN H = H + 1: IF H = 1 OR H = 2 OR H = 3 OR H = 4 THEN EXIT DO ELSE GOTO 99
IF R = 10 THEN I = I + 1: IF I = 1 OR I = 2 OR I = 3 OR I = 4 THEN EXIT DO ELSE GOTO 99
IF R = 11 THEN k = k + 1: IF k = 1 OR k = 2 OR k = 3 OR k = 4 THEN EXIT DO ELSE GOTO 99
IF R = 12 THEN M = M + 1: IF M = 1 OR M = 2 OR M = 3 OR M = 4 THEN EXIT DO ELSE GOTO 99
IF R = 13 THEN Q = Q + 1: IF Q = 1 OR Q = 2 OR Q = 3 OR Q = 4 THEN EXIT DO ELSE GOTO 99
IF R = 14 THEN S = S + 1: IF S = 1 OR S = 2 OR S = 3 OR S = 4 THEN EXIT DO ELSE GOTO 99
LOOP
PRINT X; R
PRINT RESULT$ = "Card-"; X; "Number-"; R
INPUT #1, RESULT$
NEXT
CLOSE #1[/code]
Thank you,

Card Counter
Cardcounter
 
Posts: 1
Joined: Sun Oct 21, 2007 6:02 pm

Re: QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT

Postby davidkallman » Mon Oct 22, 2007 8:10 am

Cardcounter wrote:OPEN "CardResults.txt" FOR INPUT AS #1


Hi Cardcounter,

I don't know qbasic and don't have access to a qbasic interpreter, but the above looks like it's opening CardResults.txt for data reading only. Maybe something like

OPEN "CardResults.txt" FOR OUTPUT AS #1

will work.
Cheers!

Dave
davidkallman
Former Expert
 
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Postby davidcastagna » Mon Oct 22, 2007 9:37 am

If you were trying to open the file "CardResults.txt" to store your results then davidkallman was right.

But there is another line that is wrong:

Code: Select all
INPUT #1, RESULT$


I believe it should say this:

Code: Select all
PRINT #1, RESULT$


The line you originally used is for reading from the file and not writing to the file.
================================
David, Algonquin IL, Geek
davidcastagna
Former Expert
 
Posts: 12
Joined: Sat Feb 03, 2007 7:43 am

Postby davidcastagna » Mon Oct 22, 2007 9:44 am

Also, now that I look at this closer, it looks like you also have what is known as an "Infinite Loop".

Look at what happens if the computer picks the number R=5, 4 times. The first 4 times, everything is fine and you will jump out of the DO/LOOP because of the "IF D = 1 OR D = 2 .... THEN EXIT DO".

But what happens if the computer pick R=5 for a fifth time. This time the "IF D = 1 OR D = 2 .... " will be FALSE and the computer will do "ELSE GOTO 99" instead of "THEN EXIT DO". This will make the computer go back to the label "99:" and execute there again.

Now this looks like it should work fine to randomly select 52 random card selections. However, think about what happens if all of the variables A, B, C, D, E, F, G, H, I, k, M, Q and S are all equal to 4.
================================
David, Algonquin IL, Geek
davidcastagna
Former Expert
 
Posts: 12
Joined: Sat Feb 03, 2007 7:43 am

Postby davidcastagna » Mon Oct 22, 2007 9:48 am

lol..... I apparently am not reading clearly. You do not have an infinite loop. I apologize.
================================
David, Algonquin IL, Geek
davidcastagna
Former Expert
 
Posts: 12
Joined: Sat Feb 03, 2007 7:43 am

Re: QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT

Postby OneBriiguy » Mon Oct 22, 2007 12:29 pm

Cardcounter wrote:I AM WORKING ON THE CARD COUNTING PROJECT SUGGESTED ON YOUR SITE. I AM LEARNING QBASIC IN ORDER TO DO THE PROGRAMMING FOR THE PROJECT. I HAVE PROGRAMMED THE RANDOM SORTING OF THE DECK OF CARDS. I WOULD LIKE TO PUT THE INFORMATION IN A FILE IN ORDER TO MAKE SURE THAT I AM ONLY PULLING 4 CARDS OF EACH NUMBER (4 2'S; 4 10'S, ETC). I CAN MAKE IT PRINT ON THE SCREEN, BUT I NEED TO GET THE INFORMATION INTO A FILE AND MY PROGRAM IS NOT WORKING. CAN YOU HELP ME? THIS IS WHAT I HAVE SO FAR.



Hi, Cardcounter!

I'd like to make several observations:

1) Computer programs almost always have bugs in them. Don't feel bad about the fact that it doesn't work at first. Most programs don't work correctly the first time. You are doing the right thing by trying to figure it out.

2) davidcastagna has suggested a very important skill for you to develop as you learn to program. He wrote, in part, "Look at what happens if the computer picks the number R=5, 4 times." This is called doing a code walk-through. That is, you play the role of the computer and execute the program manually, line by line, recording intermedite results on paper, etc. This is a very useful debugging technique that often reveals the source of a problem.

3) Another useful debugging technique is suggested by the comments about INPUT and PRINT statements. It is common practice to add print statements that show intermediate values. For example, at the beginning of your DO loop you could print out the values for R and A. This will give you a partial window into the inner workings of your program. Being able to see these values as your program runs can really help you figure out the point at which something went wrong. You would leave these print statements in while you are debugging, but you would remove them (or REM them out) in your final program.

4) The best way to get help from the experts in this forum is to post really well-constructed questions. To say "this doesn't work" and post the source code might give us an interesting problem to solve, but it doesn't give you the chance to find the problem yourself. I think it would be better to post a description of what went wrong - how the program misbehaved (it hung or it printed the wrong values) - and the steps you've taken so far to find the problem for yourself.

You are off to an excellent start.

Best wishes for success in your project.
Brian Castelli (OneBriiguy)
Engineering Specialist
OneBriiguy
Former Expert
 
Posts: 159
Joined: Fri Sep 30, 2005 6:31 am
Occupation: Engineer
Project Question: N/A
Project Due Date: N/A
Project Status: Not applicable

Re: QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT

Postby davidkallman » Mon Oct 22, 2007 1:02 pm

davidcastagna wrote:But there is another line that is wrong:

Code: Select all
INPUT #1, RESULT$


I believe it should say this:

Code: Select all
PRINT #1, RESULT$


The line you originally used is for reading from the file and not writing to the file.

Ah, this makes sense. There are two elements to writing/reading to/from a file: 1) how the file is opened and 2) the input/output statement. I proposed a fix to element 1 and davidcastagna proposed a fix to element 2. Again I don't know Qbasic. Hopefully, it would have some kind of error if you opened it as "input" and then tried to write to it.

The absence of an error could only happen if the output statement were missing AND the file was not opened in an output mode. This is exactly the situation here.
Cheers!

Dave
davidkallman
Former Expert
 
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Postby hhemken » Fri Oct 26, 2007 2:43 pm

Although it may be best for you to continue this project in QBasic, for future projects I would recommend against the use of QBasic. It is a discontinued language that appears to depend on obsolete modules that may or may not play well on a specific windows system. It is also obsolete as a language, an old fashioned, stripped down, and cumbersome language with no object orientation, database access, or sophisticated graphical interface features, to name a few of many shortcomings. Also, since it is obsolete and unsupported, your code will be difficult to use on other computers or to share with other users.

There are several programming languages that are robust, actively maintained, free, and with modern features. Most of them are also cross-platform, and run on practically any operating system.

In no particular order:

Python
http://www.python.org
http://www.activestate.com (for MS Windows users)

Perl
http://www.perl.org
http://www.cpan.org
http://www.activestate.com (for MS Windows users)

Java
http://java.sun.com

Pascal
http://www.freepascal.org/
http://www.codegear.com/products/delphi/win32

C++
http://www.bloodshed.net/dev/devcpp.html (use Dev-C++ 5.0)
http://www.trolltech.com/download/opensource.html (works well with Dev-C++ 5.0)

Tcl/Tk
http://www.tcl.tk/software/tcltk/
http://www.activestate.com (for MS Windows users)

Ruby
http://www.ruby-lang.org/en/
http://www.activestate.com (for MS Windows users)

If you are on a Windows computer, and an advanced user, you can install and use Cygwin, which provides a Linux-like interface at the command line. Most of the above languages can be installed for use with Cygwin:
http://www.cygwin.com

If you set up Linux on a PC, you will have access to all of the above languages and much, much more, all for free:
http://www.ubuntu.com/
http://fedora.redhat.com
http://www.us.debian.org/
[several others]

There are also BSD Unix variants available for free:
http://www.freebsd.org/
http://netbsd.org/
[others]

As you can see, the options available to you for free are enormous. There are quite a few I haven't even mentioned.

Important question: What is the "best" language for a newbie to learn? This is difficult to answer. I would recommend against C or C++. They are very powerful, but not easy for beginners to learn. Tcl/Tk is used quite a bit behind the scenes, but not so much for commonly used programs. Java, Python, and Perl are very widely used, powerful, and versatile. Of these three, I would say that Java and Python are the easiest to learn. There is a lot of free literature on the net, as well as tutorials, example code, tips, tricks, freebies, books, etc. Pascal was originally developed as a teaching language, and is very versatile and easy to use.

As if that weren't enough, there is also a huge body of program source code you can look at and use in your own programs. There are hundreds of useful programs: games, database tools, graphics tools, and a lot of stuff you have never heard of. Here are the two main repositories of open source code, available in many programming languages, and usable on Windows, Unix/Linux, and Macs:

http://freshmeat.net/
http://sourceforge.net/index.php

It is not at all an exaggeration to say that the above information can keep you busy full time for the next 20 years.
Heinz Hemken
Mentor
Science Buddies Expert Forum
hhemken
Expert
 
Posts: 260
Joined: Mon Oct 03, 2005 3:16 pm

Re: QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT

Postby davidkallman » Mon Oct 29, 2007 7:24 pm

Hi Heinz,

This is the first of two postings; it addresses the technical content of your post. The second is more history based.

Regarding the languages to be learned by a new programmer, as I understand your post they are: Java, Python and Perl, with a nod to Java and Python.

Of these two, Java is certainly the one that looks best on your resume, but I couldn't find a free version of Java. The version of Java on the Sun site, while very powerful, appears to be only a thirty day trial. Am I missing something something?

The above would suggest using Python, though it's not a language I've heard of before (maybe, I've been in outer space). Could you please give some background on Python, with a comparison to other languages?

Thanks.
Cheers!

Dave
davidkallman
Former Expert
 
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Re: QBASIC PROGRAMMING FOR CARD COUNTING MATH PROJECT - II

Postby davidkallman » Mon Oct 29, 2007 7:25 pm

Hi Heinz,

This is the second post and is more history based.

Heinz, wow! I'm impressed. Back when, I was a programming languages product manager, and you've opened up a whole lot of languages that are unfamiliar to me. Now, I have a lot of work to do, based on your posting.

Please indulge me a bit of ancient history. As languages product manager, I had mostly prosaic languages like FORTRAN and Pascal. But, I also had the very first C++ product on the market, and my strategy was to price it low - to capture market share.

Initially, C++ was called "C with Classes." I don't remember where the name C++ came from, but it's the name that stuck.

The first C++ implementation was actually a translator: C++ to C. So, you had to take the output of the C++ translator and feed it to your C compiler. (Another reason to keep the C++ price low was that the C++ translator was not a complete product, as it required a C compiler.)

Anyhow, it all worked out. C++ is where it's at, as the next C, and we have true C++ compilers (C++ to binary.)
Cheers!

Dave
davidkallman
Former Expert
 
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Postby Ray Trent » Tue Oct 30, 2007 9:23 pm

Java is certainly a popular language these days for many things, and it's cross platform. Learning it vs. C++ is a tradeoff between learning about more modern software engineering concepts with Java vs. learning more about how computers work internally via C++, which is definitely more low-level.

I haven't tried it lately, but Sun's Java development tool suite appears to me to still be free to members of SDN (Sun Developer Network) which is free to join.

If you're already familiar with BASIC, Microsoft's Visual Basic is the most common one used these days and it's available as a free download, as is their C++ compiler (called Visual Studio Express, in both cases)

Python is a good object-oriented scripting language with a lot of libraries. The documentation is a bit light compared to what you'll find on C++ or Java, though. But it's also free.

Ruby is the current fad for web development due to its many libraries and features designed for structured text generation. Haven't really done anything it it, and it might be a bit too high level for a first language, but I'm sure its proponents would say that makes it perfect :-).

Really, though, programming isn't about languages. It's about thinking in a certain structured way and then translating what you're thinking into whichever language is best suited to the task at hand.
../ray\..
Ray Trent
Expert
 
Posts: 214
Joined: Wed Aug 24, 2005 3:07 pm

Postby Craig_Bridge » Wed Oct 31, 2007 6:36 am

Ignoring the aspect of what language is good for which comercial purposes, the more important aspect relavant to this site is what language is small, self contained, easily learned, and easy for the experts to help out with.

Interpreted languages have always had an advantage in this area because the interpreters are designed to assist in the learning and debugging process and are typically a better choice for a first language even if they are anchient.
-Craig
Craig_Bridge
Expert
 
Posts: 1297
Joined: Mon Oct 16, 2006 11:47 am

QBASIC

Postby domplain not tall » Thu Nov 01, 2007 3:16 pm

I have recently instaled QBasic and have resaerched how to use it.For this project I do not understand how to start programing.Please help ASAP :?: :oops:
Thank you
domplain not tall
 
Posts: 2
Joined: Thu Nov 01, 2007 3:04 pm

Re: QBASIC

Postby davidkallman » Fri Nov 02, 2007 3:59 pm

Hi domplain not tall,

If you plug "QBASIC tutorial" into google, you'll get back many responses. Since you didn't mention what grade you're in, I don't know which one is the right one for you.

Some of the more intriguing entries are:

http://www.computer-books.us/basic_2.php
Free download of the popular book - QBASIC Tutorial

http://www.petesqbsite.com/sections/tut ... ners.shtml
Beginner's tutorials

Others may be more appropriate for you depending on your particular situation.
Cheers!

Dave
davidkallman
Former Expert
 
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

HI

Postby domplain not tall » Sun Nov 04, 2007 10:32 am

I am in 7th grade and my computer will not let me drraw anything
Thank you
domplain not tall
 
Posts: 2
Joined: Thu Nov 01, 2007 3:04 pm

Next

Return to Grades 9-12: Math and Computer Science

Who is online

Users browsing this forum: No registered users and 1 guest