Please Help

  • (2 Pages)
  • +
  • 1
  • 2

20 Replies - 989 Views - Last Post: 30 June 2014 - 02:42 PM Rate Topic: -----

#1 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Please Help

Posted 30 June 2014 - 12:25 PM

Hi I am pretty new to Programming and every time i run this program i get a C++ Error I am not sure if my IF THEN statements are wrong or if i am just missing something Please help me

QUESTION
Piecework workers are paid by the piece. Often, workers who produce a greater quantity of output are paid at a higher rate.
1-199 pieces completed $.50
200-399 $.55
400-599 $.60
600 or more $.65

INPUT: for reach worker, input the name and number of pieces completed. Data may be entered with READ or INPUT statements.
OUTPUT: Print an appropriate title and column headings. There should be one detail line for each worker, which shows the name, the number of pieces, and the amount earned. compute and print totals of the number of pieces and the dollar amount earned.

Processing: For each Person, compute the pay earned by multiplying the number of pieces by the appropriate price. Accumulate the total number of pieces and the total dollar amount paid.

THE PROGRAM
' ***** Program Mainline *****

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB PrintTotals
END

' ***** Initialize Variables *****

InitializeVariables:
Pieces = -1
TotPieces = 0
TotPay = 0
T1$ = "          PieceWork Weekly Report"
H1$ = "     NAME       Pieces     PAY"
D1$ = "\         \     ###        ###"
TL$ = "    TOTALS      ###        ###"
RETURN

' ***** Print Headings ***

PrintHeadings:
PRINT
PRINT T1$
PRINT
PRINT H1$
PRINT
PRINT
RETURN

' ***** Process Detail ***

ProcessDetail:
GOSUB ReadData
DO UNTIL UCASE$(NAM$) = "END"
    GOSUB CalculateAnswer
    GOSUB PrintDetail
    GOSUB ReadData
LOOP
RETURN

' ***** Read Input Data ****

ReadData:
READ Nam$, Pieces
DATA JOHNNY BEGOOD, 265
DATA SALLY GREAT, 650
DATA SAM KLUTZ, 177
DATA PETE PRECISE, 400
DATA FANNIE FANTASTIC, 399
DATA MORRIE MELLOW, 200
DATA END, 0
RETURN

' ***** Calculate Answer *****

CalculateAnswer:

IF "Pieces" < "199" And "Peices" > "0" THEN
    PAY = Peices * .50

    ELSE
    IF "Pieces" < "399" And "Peices" > "199" THEN
        PAY = Peices * .55
        ELSE
        IF "Pieces" < "599" And "Peices" > "399" THEN
            PAY = Peices * .60
            ELSE
            IF "Pieces" > "600" THEN
                PAY = Peices * .65
                RETURN

                ' ***** Print Detail *****
                PrintDetail:
                PRINT USING D1$; Nam$, Pieces, Pay
                RETURN

                ' ***** Print Totals *****
                PrintTotals:
                PRINT
                PRINT
                PRINT
                RETURN

                ' ***** End of Program *****



PLEASE Help thanks

This post has been edited by modi123_1: 30 June 2014 - 12:28 PM
Reason for edit:: please use the 'code' button in the editor


Is This A Good Question/Topic? 0
  • +

Replies To: Please Help

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 9572
  • View blog
  • Posts: 36,253
  • Joined: 12-June 08

Re: Please Help

Posted 30 June 2014 - 12:29 PM

Quote

Hi I am pretty new to Programming and every time i run this program i get a C++ Error I am not sure if my IF THEN statements are wrong or if i am just missing something Please help me

Perhaps explain the error you are getting, the error text, and what line it is happening on.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Please Help

Posted 30 June 2014 - 12:29 PM

You have posted in the VB6 forum but mention C++.. but the code is neither.
What is it? Some version of BASIC?
Was This Post Helpful? 0
  • +
  • -

#4 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Re: Please Help

Posted 30 June 2014 - 12:32 PM

View Postandrewsw, on 30 June 2014 - 12:29 PM, said:

You have posted in the VB6 forum but mention C++.. but the code is neither.
What is it? Some version of BASIC?

IT is qb64 and i am getting an error stating "C++ compilation failed"

it is a BASIC Program
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Please Help

Posted 30 June 2014 - 12:43 PM

I don't use qb64 but you have spelt Pieces differently in a number of places - I would fix this first.

Also
IF "Pieces" < "399" And "Peices" > "199" THEN

I assume you should be checking a variable named Pieces against a number 399, not comparing strings.
Was This Post Helpful? 0
  • +
  • -

#6 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Re: Please Help

Posted 30 June 2014 - 01:14 PM

I Have checked again and still the same problem :hammer: C++ Compilation FAILED ERROR

THIS is the updated Version Of the CODE "THE CODE is in BASIC" I am using QB64 TO DO this

' ***** Program Mainline *****

CLS
GOSUB InitializeVariables
GOSUB PrintHeadings
GOSUB ProcessDetail
GOSUB PrintTotals
END

' ***** Initialize Variables *****

InitializeVariables:
Pieces = -1
TotPieces = 0
TotPay = 0
T1$ = "          PieceWork Weekly Report"
H1$ = "     NAME       Pieces     PAY"
D1$ = "\         \     ###        ###"
TL$ = "    TOTALS      ###        ###"
RETURN

' ***** Print Headings ***

PrintHeadings:
PRINT
PRINT T1$
PRINT
PRINT H1$
PRINT
PRINT
RETURN

' ***** Process Detail ***

ProcessDetail:
GOSUB ReadData
DO UNTIL UCASE$(NAM$) = "END"
    GOSUB CalculateAnswer
    GOSUB PrintDetail
    GOSUB ReadData
LOOP
RETURN

' ***** Read Input Data ****

ReadData:
READ Nam$, Pieces
DATA JOHNNY BEGOOD, 265
DATA SALLY GREAT, 650
DATA SAM KLUTZ, 177
DATA PETE PRECISE, 400
DATA FANNIE FANTASTIC, 399
DATA MORRIE MELLOW, 200
DATA END, 0
RETURN

' ***** Calculate Answer *****

CalculateAnswer:
IF Pieces >= 600 THEN
    Rate = .65
    ELSE
    IF Pieces >= 400 AND Pieces <= 599 THEN
        Rate = .60
        ELSE
        IF Pieces >= 200 AND Pieces <= 399 THEN
            Rate = .55
            ELSE
            IF Pieces >= 1 AND Pieces <= 199 THEN
                Rate = .50
                ELSE Rate = O
            END IF
            IF Rate > 0 THEN Pay = Pieces * Rate ELSE Pay = 0
            TotPieces = TotPieces + Pieces
            TotPay = TotPay + Pay


            RETURN

            ' ***** Print Detail *****
            PrintDetail:
            PRINT USING D1$; Nam$, Pieces, Pay
            RETURN

            ' ***** Print Totals *****
            PrintTotals:
            PRINT TotPieces
            PRINT TotPay
            PRINT
            RETURN

            ' ***** End of Program *****


This post has been edited by no2pencil: 30 June 2014 - 01:16 PM
Reason for edit:: Added Code Tags

Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5389
  • View blog
  • Posts: 27,385
  • Joined: 10-May 07

Re: Please Help

Posted 30 June 2014 - 01:16 PM

Can you please use code tags while posting code? Thank you.
Was This Post Helpful? 0
  • +
  • -

#8 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Re: Please Help

Posted 30 June 2014 - 01:18 PM

Yes sorry
Was This Post Helpful? 0
  • +
  • -

#9 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Please Help

Posted 30 June 2014 - 01:19 PM

I notice you are using the letter O rather than the number 0:
ELSE Rate = O

but I can't really help you beyond this.
Was This Post Helpful? 0
  • +
  • -

#10 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Re: Please Help

Posted 30 June 2014 - 01:21 PM

View Postandrewsw, on 30 June 2014 - 01:19 PM, said:

I notice you are using the letter O rather than the number 0:
ELSE Rate = O

but I can't really help you beyond this.

Thank You I just fixed that but still no go Lol
Was This Post Helpful? 0
  • +
  • -

#11 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Please Help

Posted 30 June 2014 - 01:22 PM

Now that the code is formatted, it looks like you are missing a couple of END IFs as well.
Was This Post Helpful? 0
  • +
  • -

#12 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Please Help

Posted 30 June 2014 - 01:37 PM

Quote

C++ Compilation FAILED ERROR

If you keep getting this same, unhelpful, error message then I am suspicious that it is not being compiled correctly, or is not configured correctly. Build, compile and run a VERY simple program, just to make sure the compile process works.
Was This Post Helpful? 0
  • +
  • -

#13 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Re: Please Help

Posted 30 June 2014 - 02:14 PM

Still a no go although i did make a new simple program and it did work so i am still not quite sure what i am doing wrong... i am trying to debug but i am not sure what needs debugging :/
Was This Post Helpful? 0
  • +
  • -

#14 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3812
  • View blog
  • Posts: 13,522
  • Joined: 12-December 12

Re: Please Help

Posted 30 June 2014 - 02:15 PM

Curiosity got the better of me.. you are missing END IFs as I mentioned. The program runs with these added:
            IF Rate > 0 THEN Pay = Pieces * Rate ELSE Pay = 0
            TotPieces = TotPieces + Pieces
            TotPay = TotPay + Pay
        END IF
    END IF
END IF

RETURN

I installed the default editor and it gives very clear messages that these are missing.

Study these changes. Every IF must have a matching END IF, unless the entire IF-statement is keyed on a single line.

This post has been edited by andrewsw: 30 June 2014 - 02:17 PM

Was This Post Helpful? 0
  • +
  • -

#15 ap1234  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-June 14

Re: Please Help

Posted 30 June 2014 - 02:24 PM

View Postandrewsw, on 30 June 2014 - 02:15 PM, said:

Curiosity got the better of me.. you are missing END IFs as I mentioned. The program runs with these added:
            IF Rate > 0 THEN Pay = Pieces * Rate ELSE Pay = 0
            TotPieces = TotPieces + Pieces
            TotPay = TotPay + Pay
        END IF
    END IF
END IF

RETURN

I installed the default editor and it gives very clear messages that these are missing.

Study these changes. Every IF must have a matching END IF, unless the entire IF-statement is keyed on a single line.

Where do you get the "editor" i must be missing that
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2