Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbie workin on class project need some insight
#11
I'll just give you some quick style pointers:

* You don't need line numbers. Get rid of them, they make your code look ugly Wink

* Also, you can comment your code with an apostrophe (') instead of REM

* If you do remove the line numbers your gotos will crash. Just replace them with a label for starters, until you learn about loops and how to completely avoid GOTO.

So your program above becomes this:

[syntax="qbasic"]' Program to calcuate Employees hours and pay
CLS
PRINT " NAME ", "HOURS ", "PAY"
PRINT

' employees name, hours worked, pay rate
DATA Alley Oop, 40, 6.25
DATA Jack Daniels, 48, 6
DATA Johnny Walker, 40, 6.50
DATA last one, 0, 0

' E$=employee name hr=hours worked pay=payrate
nextemp:
READ e$, hr, pay
IF pay = 0 THEN GOTO 180
' ot=overtime pay, othr=overtime hours
ot = pay * 1.5
othr = hr - 40
' grpay=gross pay
IF hr > 40 THEN grpay = 40 * pay + othr * ot
IF hr < 41 THEN grpay = hr * pay
PRINT USING "& ## $###.##"; e$; hr; grpay
' topay= total pay
topay = grpay + grpay + grpay
GOTO nextemp

PRINT
PRINT USING "Total pay is $###.##"; topay
END [/syntax]

(if you want to post highlighted code, put it in [syntax="qbasic"][/syntax] tags)

Anyway, you need to change this line:

topay = grpay + grpay + grpay

See if you can work it out!
Reply
#12
You almost got it...try using these lines (replace the ones you have):

Code:
100 PRINT USING "\          \   ##         $###.##"; e$; hr; grpay
110 topay = topay + grpay
Reply
#13
Hehe, glad to know I did okay. How do I do the types? Anyway, sorry for giving you the whole thing, I am kind of a newbie myself (that is to Qbasic, I use to use visual basic, quite the same). There is no such thing as too n00bish here, don't worry.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#14
Torahteen, I really have not used your prog,(yet heheh) I already had this much done, so dont feel bad about give me some pointers. I need all the help I can get. Big Grin I have spent many many many.....hours just to get to this point. I have no books just a 25 page hand out on the VERY basic stuff. I thought all this up myself, plus I am making a statement for ever line the project requested so its not all my credit.
assman exits stage left
Reply
#15
Thank you Oracle, I will use your advise and correct my layout. I actualy knew about the ( ' ) for REM but I felt my professor would want me to do it the long way. I picked up ont the ( ' ) after reading many different tutorial and I could not figure the line starting with the ( ' )
hehehe Now I know! Also could you show me a sample of how to post code in color, I read but not understanding.

Thank you again for your comments! Big Grin

Don
assman exits stage left
Reply
#16
Plasma, Thanks for the help. I understand the "print using" line but could your explain how the the "topay=topay + grpay" It works but I really want to understand what its doing. I may not use Qbasic forever but I no what I learn here will help me with other languages I will need to learn before I get my degree. Atleast that my take on it!

Thanks again

Don
assman exits stage left
Reply
#17
Think like a computer... Smile

At the beginning of your program, topay = 0 (because QB is nice and initializes all variables to 0)

The first time through the "loop", the employee is Alley Oop, and you calculate grpay to be 250. topay is then set to itself (currently 0), plus grpay (currently 250), so topay now = 250.

The second time through, employee is Jack Daniels, grpay is now 312. Again, topay is set to itself (currently 250), plus grpay (currently 312), so topay now = 562

The third time through, employee is Johnny Walker, grpay is calculated to be 260. Topay is yet again set to itself (currently 562), plus grpay (currently 260), making topay = 822

Your program now exits the loop with topay equal to the sum of all the payments.


Your method (topay = grpay + grpay + grpay) doesn't work because you are changing grpay for each iteration of the loop. Unless you save the value of grpay somewhere at the end of the loop (in an array, for example), it's changed the next time around. So when you tell the computer to set the topay to grpay + grpay + grpay, you're just saying topay = grpay * 3, because grpay is always the same.
Reply
#18
Thanks man! Thats just what I needed. it makes sense to me now. :bounce: So as long as the terminator statement is not met, it will keep adding grpay, correct?

Thanks for takin the time to "show me the light"

Don
assman exits stage left
Reply
#19
Glad I could help. Oh, and I noticed that I forgot to use quotes ("")on my print lines. What plasma said is a good idea, I use it alot.
quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Reply
#20
Code:
QBASIC:
CLS
PRINT "your name"
END

Ok back to the books!!!
assman exits stage left
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)