Qbasicnews.com
February 22, 2020, 08:13:38 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1] 2
  Print  
Author Topic: Newbie workin on class project need some insight  (Read 6495 times)
Don W
New Member

Posts: 14


« on: May 10, 2004, 09:01:52 PM »

I am enrolled in a SC401 class and my final assignment is to write a program that takes employees names, hours worked and pay rate, and calculates the overtime then print the information with the pay for each emp and then show total paid for all three emp.  (I am not asking for someone to do this, just some help  Cheesy )  I have got it to show the emp, hr and gross pay for each emp, including overtime, and I also have a "total pay is  $###.##"  but its reading the information for the last loop before the terminator ...ie totalpay=pay + pay + pay  ( my first "gross pay" was 250.00, my secnd was 312.00, third 260.00 but its shows 780.00 as total pay which is 260.00 * 3)  Any pointers or where I may find examples to view would be wonderful.

Don
Logged

assman exits stage left
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #1 on: May 10, 2004, 09:48:14 PM »

totalpay=pay + pay + pay?
assuming that your are using the same variable for each pay and the it is last set to 260.... it does exactly what you told it to do
use different variables... or maybe *gasp* arrays

edit: also some code would be nice
edit2: welcome to the forums  :king:
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Don W
New Member

Posts: 14


« Reply #2 on: May 10, 2004, 09:59:05 PM »

Thank you,
my prog reads the data then calculated the pay * hours and the overtime pay * hours, if any, then prints the empl infor.
(employeename, hours##, grosspay$###.##)
once it reads the termintor in my data it goto total pay line
 I have tryed  array, at least thats what I think it is

for i=0 to 2
next i

but it did nothing.  am I head the right direction?

I can post my code tonight when I get home.

Thanks again
Logged

assman exits stage left
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #3 on: May 10, 2004, 10:06:22 PM »

thats becauase thats not an array. thats a FOR NEXT loop

an array is an arrangement of memory elements in one or more planes.

or in other words a bunch of boxes stacked like this
Code:
|_|_|_|_|_|
|_|_|_|_|_|
|_|_|_|_|_|
|_|_|_|_|_|
|_|_|_|_|_|

space 3,3 is
Code:
|_|_|_|_|_|
|_|_|_|_|_|
|_|_|*|_|_|
|_|_|_|_|_|
|_|_|_|_|_|

ok to dimension an array you

DIM array (x,y)

x and y can be any number

oh yea also you can also have only one row

DIM array(x)


Code:
DIM emppay(3)
emppay(1) = 250.00
emppay(2) = 312.00
emppay(3) = 260.00
FOR i = 1 TO 3
totalpay = emppay(i) + totalpay
NEXT i
PRINT totalpay
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Don W
New Member

Posts: 14


« Reply #4 on: May 10, 2004, 11:42:32 PM »

Oh, OK, I was wrong.  I will read some more on arrays  

thanks for the information

Should I post my code?
Logged

assman exits stage left
Torahteen
Ancient Guru
****
Posts: 744



« Reply #5 on: May 10, 2004, 11:43:34 PM »

Ooh Ooh! Can I try!
I hope this is what you are looking for. (And correct me for any mistakes) Can you have code before arrays? Oh, and where do you put TYPE statments?

Code:

TYPE employee
name$
wage!
hours!

INPUT "How many employees do you want to record?", numemp%

DIM emppay(numemp%)
DIM employee(numemp%) AS employee

FOR i=1 to numemp%

PRINT "Employee name:"
INPUT , employee.name$(i)
PRINT "Emplyee wage per hour:"
INPUT , employee.wage!(i)
PRINT "Enployee's hours worked:"
INPUT , employee.hours!(i)

emppay(i) = employee.wage!(i) * employee.hours!(i)

next i

`Now, print it nicely
format$ = "/                            / $$##.##/     ##    / $$#,###.##"
PRINT          Employee Name     Wage        Hours     Total Pay
PRINT          ---------------------    --------       --------     ------------------

FOR i = 1 to numemp%

  PRINT USING , format$ ; employee.name$(i); employee.wage!(i); employee.hours!(i); emppay!(i)

next i


Did I do that right? Well, until you get confirmation, don't get any ideas.[/code]
Logged

quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #6 on: May 10, 2004, 11:51:13 PM »

youd did the TYPE wrong but beside that (and with a little modifacation) it would do exactly what Don wants it to do

but Torahteen don't post the whole completed thing. let him do some work =P
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Don W
New Member

Posts: 14


« Reply #7 on: May 10, 2004, 11:53:34 PM »

well, mine is not so nice.  Actualy I am more of a newbie than maybe this forum is for.  I have been reading alot but need to see it to understand.  I will get it!  Just lookin for some assistance in finding my answer.  

Thanks

Don
Logged

assman exits stage left
whitetiger0990
__/--\__
*****
Posts: 2964



WWW
« Reply #8 on: May 10, 2004, 11:56:02 PM »

Quote from: "Don W"
well, mine is not so nice.  Actualy I am more of a newbie than maybe this forum is for.  I have been reading alot but need to see it to understand.  I will get it!  Just lookin for some assistance in finding my answer.  

Thanks

Don


hehe nobodies code is perfect. and actually you havn't seen any of the complete newbies here. keep going at it.

*yawn* tommorow i will return!
Logged


[size=10]Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.[/size]
Don W
New Member

Posts: 14


« Reply #9 on: May 11, 2004, 12:57:23 AM »

This is how I wrote may program: (don't laugh) hehehe

REM Program to calcuate Employees hours and pay
CLS
0 PRINT "   NAME  ", "HOURS  ", "PAY"
5 PRINT
6 rem employees name, hours worked, pay rate
10 DATA Alley Oop, 40, 6.25
20 DATA Jack Daniels, 48, 6
30 DATA Johnny Walker, 40, 6.50
40 DATA last one, 0, 0
41 rem E$=employee name  hr=hours worked  pay=payrate
45 READ e$, hr, pay
49 IF pay = 0 THEN GOTO 180
50 REM ot=overtime pay,  othr=overtime hours
51 ot = pay * 1.5
52 othr = hr - 40
53 REM grpay=gross pay
55 IF hr > 40 THEN grpay = 40 * pay + othr * ot
65 IF hr < 41 THEN grpay = hr * pay
100 PRINT USING "&     ##          $###.##"; e$; hr; grpay
101 rem topay= total pay
110 topay = grpay + grpay + grpay
170 GOTO 45
180 PRINT
190 PRINT USING "Total pay is               $###.##"; topay
200 END

Pretty basic, its all have have learned so far.  I just can't get the print format to work for the data, and I can't get the correct sum of all the gross pays.
Logged

assman exits stage left
oracle
*/-\*
*****
Posts: 3652



WWW
« Reply #10 on: May 11, 2004, 01:18:20 AM »

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!
Logged

Plasma
Na_th_an
*****
Posts: 1770


WWW
« Reply #11 on: May 11, 2004, 01:21:55 AM »

You almost got it...try using these lines (replace the ones you have):

Code:
100 PRINT USING "\          \   ##         $###.##"; e$; hr; grpay
110 topay = topay + grpay
Logged
Torahteen
Ancient Guru
****
Posts: 744



« Reply #12 on: May 11, 2004, 01:27:17 AM »

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.
Logged

quote="Deleter"]judging gameplay, you can adaquately compare quake 4 with pong[/quote]
Don W
New Member

Posts: 14


« Reply #13 on: May 11, 2004, 01:39:42 AM »

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.   Cheesy  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.
Logged

assman exits stage left
Don W
New Member

Posts: 14


« Reply #14 on: May 11, 2004, 01:52:34 AM »

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!  Cheesy

Don
Logged

assman exits stage left
Pages: [1] 2
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!