Totlas and Counters help

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
Guest

Totlas and Counters help

Post by Guest » Sun Dec 18, 2005 2:56 pm

Hi, could someone help me understand how Totals and Counters work and give me example of some questions.


1) Generate 40 random integers between -50 and 50 and then display how many of those number were positve.

2) Simulate the tossing of a coin 20 times, display if it was heads or tails for each toss and then display how many heads were tossed and how many tails were tossed.

3)Write a program that asks for a password, do not let the user continue until the password is geussed correctly. At the end display how many tries it took to get the correct password.

Help would be really appreciated, thanks.

User avatar
Nodtveidt
Veteran
Posts: 826
Joined: Sun Jul 25, 2004 4:24 am
Location: Quebradillas, PR
Contact:

Post by Nodtveidt » Sun Dec 18, 2005 5:12 pm

As soon as you've showed us how much of your homework assignment you've already done, I'm sure someone here would be willing to help you out. :D

Guest

Post by Guest » Sun Dec 18, 2005 9:30 pm

Nekrophidius wrote:As soon as you've showed us how much of your homework assignment you've already done, I'm sure someone here would be willing to help you out. :D
Yes, exactly my feelings.
And by the way, since you're asking for code, not just a quick answer, why don't you register and become a member? It's nice to know who you're spending time and effort to help. This is a QBasic programming forum, not a question/answer radio program.
*****

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Sun Dec 18, 2005 9:34 pm

The above post was mine. (Moneo)
We've been having problems with the Log in, but I doub't that was the problem with the author of this thread.
*****
If you are ahead of me, lead.
If you are behind me, follow.
If you are not doing anything,
Get out of the way.

Guest

Post by Guest » Sun Dec 18, 2005 9:54 pm

actually, it was the problem with the author if this thread...that was me thinking I was logged in.

anyway, for the unit we received about 10 worksheets with about 10 questions in each of them. In the beginning we started off with simple things like variables, and then we moved onto things like If statements and do loops. I was keeping up with most of it, up until we got to random numbers, I figured out how most of it works but I can't figure out how to choose from negative and positive random numbers (hence the reason why I couldn't do one of those questions) I understand most of it, the only trouble I have is with Totals, Counters, and some trouble with random numbers. If someone could show me how the three questions work I should be able to figure out how counters work and get the answer to my only question about random numbers.

Ziggy
Newbie
Posts: 2
Joined: Sun Dec 18, 2005 1:39 pm

Post by Ziggy » Sun Dec 18, 2005 9:55 pm

hmm...the problem still seems to be occurring...I'm not sure if this will show up under guest or as my actuall account on these boards (Ziggy).

Z!re
Veteran
Posts: 887
Joined: Wed Aug 04, 2004 11:15 am

Post by Z!re » Sun Dec 18, 2005 11:42 pm

The cookie problems are solved. Gentlemen, clear your cookie caches.
I have left this dump.

benjiboy
Coder
Posts: 11
Joined: Wed Dec 14, 2005 2:18 am
Location: Norfolk, England

Post by benjiboy » Mon Dec 19, 2005 8:29 am

This still looks guest wants us to do his homework...
Some hints:-

-1 < ? < 1

Figure out what the question mark is and you have the conditional for testing positive or negative...

How do you count?
You add a number to the number you already have...
1+1=2
?+1=3
?+1=4
change the ? to a letter and you have algebra
x+1=4
so x is what?
and what was it in the previous statement?
Turn the algebraic statement around and you have a basic assignment statement:-
?=?+1

The rest, as they say is up to you...
Benjiboy

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Be who you are, not who others say you should be.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

summing and counting

Post by Zim » Mon Dec 19, 2005 12:18 pm

Ok, here's a couple of lines of code for you:

To count something you must start with a counter set to zero!

Code: Select all

sumpos=0
To test if something is positive check if it's greater than zero:

Code: Select all

if num>0 then.....
To count, add "1" to the counter (conditionally, of course):

Code: Select all

if num>0 then sumpos=sumpos+1
Play with that a little and see if you begin to understand.
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---

Guest

Post by Guest » Mon Dec 19, 2005 3:28 pm

Anonymous wrote:actually, it was the problem with the author if this thread...that was me thinking I was logged in.
......
Ok, so who are you anyway?

Here's some code to generate random numbers between -50 and 50. But bear in mind that zero will be one of these random numbers.

Code: Select all

defint a-z
RANDOMIZE TIMER

Lower = -50
Upper = 50
R = INT(RND * (Upper - lower + 1)) + lower
R is the random number between -50 and 50.
*****

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Mon Dec 19, 2005 3:30 pm

Again, the above post was mine (Moneo).
*****

Ziggy
Newbie
Posts: 2
Joined: Sun Dec 18, 2005 1:39 pm

Post by Ziggy » Mon Dec 19, 2005 5:57 pm

Anonymous wrote:
Anonymous wrote:actually, it was the problem with the author if this thread...that was me thinking I was logged in.
......
Ok, so who are you anyway?
I thought I was logged in...again...and when I post this It might show up under guest...but as I stated before, I am registered as Ziggy. The help that peple have provided is more than enough, I should be able to figure out how to do most of it from here.

moneo
Veteran
Posts: 451
Joined: Tue Jun 28, 2005 7:00 pm
Location: Mexico City, Mexico

Post by moneo » Mon Dec 19, 2005 8:04 pm

Ok, Ziggy. Good luck. Let us know if you have any other problems or needs.
*****

Guest
Veteran
Posts: 128
Joined: Sun Aug 14, 2005 8:33 pm
Location: Forest Lake, MN
Contact:

Post by Guest » Mon Dec 19, 2005 8:50 pm

Be ahead of your class and understand the language better. Read Vic's Tutorials...

Post Reply