Archived

This topic is now archived and is closed to further replies.

Drevay

Stuck on a QBASIC assignment, really need help :C

Recommended Posts

Now, in this assignment I must use DO WHILE LOOPing, to make the computer ask me the users name, the users gender, and the users age, the questions will keep looping, keeping track of how many males and females and averaging the age of each sex, then when the user name END is entered, the program displays in a chart (know how to make the char atleast :C ), the number of males, females, and the average age of each sex. Please ... help ... me :C! Of course that''''s just my opinion, I could be wrong. -)(-Dennis Miller-)(-

Share this post


Link to post
Share on other sites
Errr.... I didn''t see a question there. Do you really expect someone to write the program for you?

We aren''t going to do your homework. Try it yourself. If you have specific questions about the language or something, then ask those. But don''t ask them unless you''ve already looked for the answer yourself.


But... but that''s what HITLER would say!!

Share this post


Link to post
Share on other sites
Oh sorry, I should have been more specific.... >.>

You see I''ve tried for hours here, I just don''t know where to go, I''m on page 44 of the manual, miles ahead of my class, and here I get into a snag.

Now, I feel really stupid asking this question of course, but I mean, I know I will have to use some IF THEN satements, of course some DO WHILE LOOP statements, and maybe even work out some equations for the computer to follow by...

I was thinking something like this

In the if statement -

IF sGender = "male" THEN
nTotalmale = + 1
ELSE IF sGender = "female" THEN
nTotalfemale = + 1

Now that''s what I THINK should work, but.....it doesn''t....what am I missing?

Also how will I average out all of the ages?
?_?
I am .... really stuck, I hate to sound like such a newbie.....sorry :C

Of course that''''s just my opinion, I could be wrong.
-)(-Dennis Miller-)(-

Share this post


Link to post
Share on other sites
Uhmmm... Whatever your trying to do with the =+, don't... you might be thinking of += and I don't even think you can use that operator in qbasic... do totalMales = totalMales + 1.....

your question about averaging is easy... you need a variable to keep track the total ages combined...

so when someone enters their age do:

totalMalesAge = totalMalesAge + WhateverAgeTheUserEntered
numberOfMaleAges = numberOfMaleAges + 1

then to get the average do...

average = totalMaleAge / numberOfMaleAges...

im not rereading what i typed to make sure i didn't do anythign stupid but you should get the idea!




[edited by - anachronism on March 3, 2003 2:02:44 PM]

Share this post


Link to post
Share on other sites


name$ = ""
males = 0
females = 0
totalage = 0
numberofpersons = 0

DO WHILE name$ <> "END"
input "Name: ", name$
input "Gender: ", gender$
input "Age: ", age

totalage = totalage + age
numberofpersons = numberofpersons + 1

IF gender = "Male" THEN
males = males + 1
ELSE
females = females + 1
END IF

LOOP

'Finished

PRINT "Number of males: ", males
PRINT "Number of females: ", females
PRINT "Average Age: ", (totalage / numberofpersons)



-------

It has been a while since I used QBasic, so there could be some errors. And it is up to you to keep track of the average age of the genders... you have to learn something too

[edited by - frankie68 on March 3, 2003 3:04:48 PM]

Share this post


Link to post
Share on other sites
It''s so weird not seeing semicolons at the end of almost every line Makes me wanna fire up GW-BASIC again and mess with LINE NUMBERS (yuck )

Share this post


Link to post
Share on other sites
hmmmmmm....

Ok, I have to make that into modular (subdivision) QBASIC now, or it won''t count for marks.....thanks :D

Of course that''''s just my opinion, I could be wrong.
-)(-Dennis Miller-)(-

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
use the lcase$ function so you can test for "male" or "female" instead of all the different letters having caps.

ie

if lcase$(gender$) = "male" then males = males + 1
else females = females + 1

Share this post


Link to post
Share on other sites