Author Topic: Help with program  (Read 1889 times)

0 Members and 1 Guest are viewing this topic.

Offline Aeveus

  • Newbie
  • Posts: 5
    • View Profile
Help with program
« on: May 11, 2020, 02:18:31 pm »

Hi there, I know this program might look crude but I've almost got it to do what I want. I can't get it to display the everything at the end, it seems to only show the two that are above 80000.

Code: QB64: [Select]
  1. GOSUB InitializeVariables
  2. GOSUB PrintHeadings
  3. GOSUB ProcessDetail
  4. '
  5. '****************************InitializeVariables**************************
  6. InitializeVariables:
  7. T1$ = "     XYZ COMPANY"
  8. H1$ = "Salesperson          Earnings"
  9. D1$ = "\               \          $$#####"
  10. '
  11. '***************************** Print Headings ****************************
  12. PrintHeadings:
  13. PRINT T1$
  14. PRINT H1$
  15. '**************************** Process Detail *****************************
  16. ProcessDetail:
  17. GOSUB ReadData
  18. DO UNTIL Name$ = "END"
  19.     GOSUB CalculateAnswer
  20.     GOSUB PrintDetail
  21.     GOSUB ReadData
  22. '************************* Print Detail ******************************
  23. PrintDetail:
  24. PRINT USING D1$; Name$,Pay
  25. '*************************** Read Data *************************************
  26. ReadData:
  27. READ Name$, Sales
  28. DATA JILL JOHNSON,90000
  29. DATA DON WILLIAMS,70000
  30. DATA DEE JONES,95000
  31. DATA AL ENNIS,40000
  32. '************************** Calculate Answer ******************************
  33. CalculateAnswer:
  34. IF Sales > 80000 THEN
  35.     PAY = (SALES * 1.1) + 10500
  36.     ELSE
  37.     PAY = SALES + 10000
  38.  
  39.  

Marked as best answer by Aeveus on May 11, 2020, 01:35:41 pm

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Help with program
« Reply #1 on: May 11, 2020, 03:13:22 pm »
Hi Aeveus

welcome to the forum of QB64!

I can see that you like make SubProgram by GOSUB: RETURN... so you mustn't pass variables as parameters.

It seems to me that you have missed to type the closing statement for GOSUB at line 34
Code: QB64: [Select]
for the subprogram started by label PrintDetail:

try if now also on your pc all run ok!
Programming isn't difficult, only it's  consuming time and coffee

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Help with program
« Reply #2 on: May 11, 2020, 04:01:21 pm »
Hi Aeveus

Another approach would be to eliminate the GoSub PrintDetail all together and simply replace it in your Do Loop with the Print Using statement

Code: QB64: [Select]
  1. DO UNTIL NAME$ = "END"
  2.     GOSUB CalculateAnswer
  3.     PRINT USING D1$; NAME$,Pay
  4.     GOSUB ReadData


Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Help with program
« Reply #3 on: May 11, 2020, 04:18:21 pm »
Hi Aeveus, welcome to the forum!

Which is clearer to read yours (fixed by TempodiBasic) or this:
Code: QB64: [Select]
  1. '
  2. '****************************InitializeVariables**************************
  3. T1$ = "     XYZ COMPANY"
  4. H1$ = "Salesperson          Earnings"
  5. D1$ = "\               \          $$#####"
  6. '***************************** Print Headings ****************************
  7. PRINT T1$
  8. PRINT H1$
  9. DO ' ******************* Process pay
  10.  
  11.     'ReadData:
  12.     READ NAME$, Sales
  13.     IF NAME$ = "END" THEN EXIT DO
  14.  
  15.     'calculateAnswer:
  16.     IF Sales > 80000 THEN
  17.         Pay = (Sales * 1.1) + 10500
  18.     ELSE
  19.         Pay = Sales + 10000
  20.     END IF
  21.  
  22.     'PrintDetail:
  23.     PRINT USING D1$; NAME$, Pay
  24.  
  25. DATA JILL JOHNSON,90000
  26. DATA DON WILLIAMS,70000
  27. DATA DEE JONES,95000
  28. DATA AL ENNIS,40000
  29.  
  30.  

The opposite of spaghetti code is "shredded wheat" code from over use of GOSUB. Just advice, I know you are just getting started. :)

BTW XYZ is not going to be in business long paying their employees more than their sales, yikes!

Offline Aeveus

  • Newbie
  • Posts: 5
    • View Profile
Re: Help with program
« Reply #4 on: May 11, 2020, 05:36:25 pm »
Thanks for the help as always! You guys are the best