Totlas and Counters help
Totlas and Counters help
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.
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.
Yes, exactly my feelings.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.
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.
*****
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.
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.
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...
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.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Be who you are, not who others say you should be.
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
summing and counting
Ok, here's a couple of lines of code for you:
To count something you must start with a counter set to zero!
To test if something is positive check if it's greater than zero:
To count, add "1" to the counter (conditionally, of course):
Play with that a little and see if you begin to understand.
To count something you must start with a counter set to zero!
Code: Select all
sumpos=0
Code: Select all
if num>0 then.....
Code: Select all
if num>0 then sumpos=sumpos+1
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
--- Time flies like an arrow, but fruit flies like a banana ---
Ok, so who are you anyway?Anonymous wrote:actually, it was the problem with the author if this thread...that was me thinking I was logged in.
......
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
*****
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.Anonymous wrote:Ok, so who are you anyway?Anonymous wrote:actually, it was the problem with the author if this thread...that was me thinking I was logged in.
......