Search code examples
pseudocode

Pseudocode Pre release Material IGCSE


I have attempted a pre release task for an IGCSE pre release(https://bestexamhelp.com/exam/cambridge-igcse/computer-science-0478/2017/0478-s17-pm-22.php) here is attached the documentation for the pseudocode(http://alongside.us/pseudocode/0478_pseudocode_guide.pdf) and I have run the program in VS code using a pcse extension which can be found here(https://github.com/virchau13/pcse-ext). I have successfully managed to complete and produce task 1 however my second task will not run. I am unable to identify the error as the program simply doesn't run despite only outputting a single message. Any help would be greatly appreciated.

DECLARE SeniorCitizenNames: ARRAY[1:36] OF STRING
DECLARE individualCollectedAmount: ARRAY[1:36] OF REAL
DECLARE numSeniorCitizens: INTEGER
DECLARE Carers: INTEGER
DECLARE numPeople: INTEGER
DECLARE coachCost: INTEGER
DECLARE ticketCost: REAL
DECLARE mealCost: REAL
DECLARE totalCost: REAL
DECLARE costPerPerson: REAL
DECLARE totalAmountCollected: REAL
DECLARE hasMorePeople: BOOLEAN
DECLARE Carer1: STRING
DECLARE Carer2: STRING
DECLARE Carer3: STRING

OUTPUT "Enter Number of Senior Citizens:"
INPUT numSeniorCitizens // minimum 10 maximum 36

WHILE numSeniorCitizens < 10 OR numSeniorCitizens > 36 DO
    OUTPUT "INVALID. The number of Senior Citizens must be between 10 and 36 inclusive. 
    Please enter another number:"
    INPUT numSeniorCitizens // minimum 10 maximum 36
ENDWHILE
// Going to the trip
Carers <- 2
IF numSeniorCitizens > 24 
    THEN 
        Carers <- 3
ENDIF

numPeople <- numSeniorCitizens + Carers

IF numPeople >= 12 AND numPeople <= 16
    THEN 
        coachCost <- 150
        mealCost <- 14.00
        ticketCost <- 21.00
    ELSE
        IF numPeople >= 17 AND numPeople <= 26
            THEN
                coachCost <- 190
                mealCost <- 13.50
                ticketCost <- 20.00
            ELSE
                IF numPeople >= 27 AND numPeople <= 39
                    THEN
                        coachCost <- 225
                        mealCost <- 13.00
                        ticketCost <- 19.00
                ENDIF
        ENDIF
ENDIF

totalCost <- coachCost + mealCost * numPeople + ticketCost * numPeople
costPerPerson <- totalCost / numSeniorCitizens

totalAmountCollected <- 0

FOR count <- 1 TO numSeniorCitizens
    OUTPUT "Enter the names of the senior citizens and the amount they paid"
    INPUT SeniorCitizenNames[count]
    INPUT individualCollectedAmount[count]
    totalAmountCollected <- totalAmountCollected + individualCollectedAmount[count]
NEXT

OUTPUT "Are there more senior citizens to be added?"
INPUT hasMorePeople

WHILE numSeniorCitizens < 36 AND hasMorePeople == TRUE DO
    numSeniorCitizens <- numSeniorCitizens + 1
    OUTPUT "Enter the names of the senior citizens and the amount they paid"
    INPUT SeniorCitizenNames[numSeniorCitizens]
    INPUT individualCollectedAmount[numSeniorCitizens]
    totalAmountCollected <- totalAmountCollected + 
    individualCollectedAmount[numSeniorCitizens]

    OUTPUT "Are there more senior citizens to be added?"
    INPUT hasMorePeople
ENDWHILE

OUTPUT "the first carers name"
INPUT Carer1
OUTPUT "The second carers name is:"
INPUT Carer2

IF numSeniorCitizens > 24 
    THEN 
        Carers <- 3
        OUTPUT "The third carers name is:"
        INPUT Carer3
ENDIF

numPeople <- numSeniorCitizens + Carers

FOR count <- 1 TO numSeniorCitizens
    OUTPUT SeniorCitizenNames[count]
NEXT

OUTPUT "The first and second Carers names are", Carer1, "and", Carer2
IF numSeniorCitizens > 24 
    THEN 
        OUTPUT "The third carers name is", Carer3
ENDIF

OUTPUT "The total cost of this trip is $", totalCost // The totoal cost
OUTPUT "The cost per person for this trip is $", costPerPerson // The cost per person
OUTPUT "THe total amount collected is $", totalAmountCollected // amount of money collected 
by organiser

Solution

  • I do not know if the pseudocode below will resolve the issue(s), but I have slightly edited some of your original pseudocode:

    DECLARE SeniorCitizenNames: ARRAY[1:36] OF STRING
    DECLARE individualCollectedAmount: ARRAY[1:36] OF REAL
    DECLARE numSeniorCitizens: INTEGER
    DECLARE Carers: INTEGER
    DECLARE numPeople: INTEGER
    DECLARE coachCost: INTEGER
    DECLARE ticketCost: REAL
    DECLARE mealCost: REAL
    DECLARE totalCost: REAL
    DECLARE costPerPerson: REAL
    DECLARE totalAmountCollected: REAL
    DECLARE hasMorePeople: BOOLEAN
    DECLARE Carer1: STRING
    DECLARE Carer2: STRING
    DECLARE Carer3: STRING
    
    OUTPUT "Enter Number of Senior Citizens:"
    numSeniorCitizens <- USERINPUT // minimum 10 maximum 36
    
    
    WHILE numSeniorCitizens < 10 OR numSeniorCitizens > 36:
        OUTPUT "INVALID. The number of Senior Citizens must be between 10 and 36 inclusive. Please enter another number:"
        numSeniorCitizens <- USERINPUT // minimum 10 maximum 36
    ENDWHILE
    // Going to the trip
    Carers <- 2
    IF numSeniorCitizens > 24 THEN:
        Carers <- 3
    ENDIF
    
    numPeople <- numSeniorCitizens + Carers
    
    IF numPeople >= 12 AND numPeople <= 1 THEN: 
        coachCost <- 150
        mealCost <- 14.00
        ticketCost <- 21.00
        ELIF numPeople >= 17 AND numPeople <= 26 THEN:
                coachCost <- 190
                mealCost <- 13.50
                ticketCost <- 20.00
        ELIF numPeople >= 27 AND numPeople <= 39 THEN:
                        coachCost <- 225
                        mealCost <- 13.00
                        ticketCost <- 19.00
                    ENDIF
            ENDIF
    ENDIF
    
    totalCost <- coachCost + mealCost * numPeople + ticketCost * numPeople
    costPerPerson <- totalCost / numSeniorCitizens
    
    totalAmountCollected <- 0
    
    FOR count <- 1 TO numSeniorCitizens:
        OUTPUT "Enter the names of the senior citizens and the amount they paid"
        SeniorCitizenNames[count] <- USERINPUT
        individualCollectedAmount[count] <- USERINPUT
        totalAmountCollected <- totalAmountCollected + individualCollectedAmount[count]
    
    OUTPUT "Are there more senior citizens to be added?"
    hasMorePeople <- USERINPUT
    
    WHILE numSeniorCitizens < 36 AND hasMorePeople == TRUE:
        numSeniorCitizens <- numSeniorCitizens + 1
        OUTPUT "Enter the names of the senior citizens and the amount they paid"
        SeniorCitizenNames[numSeniorCitizens] <- USERINPUT
        individualCollectedAmount[numSeniorCitizens] <- USERINPUT
        totalAmountCollected <- totalAmountCollected + 
        individualCollectedAmount[numSeniorCitizens]
    
        OUTPUT "Are there more senior citizens to be added?"
        hasMorePeople <- USERINPUT
    ENDWHILE
    
    OUTPUT "the first carers name"
    Carer1 <- USERINPUT
    OUTPUT "The second carers name is:"
    Carer2 <- USERINPUT
    
    IF numSeniorCitizens > 24 THEN:
        Carers <- 3
        OUTPUT "The third carers name is:"
        Carer3 <- USERINPUT
    ENDIF
    
    numPeople <- numSeniorCitizens + Carers
    
    FOR count <- 1 TO numSeniorCitizens:
        OUTPUT SeniorCitizenNames[count]
    
    OUTPUT "The first and second Carers names are", Carer1, "and", Carer2
    IF numSeniorCitizens > 24 THEN: 
        OUTPUT "The third carers name is", Carer3
    ENDIF
    
    OUTPUT "The total cost of this trip is $", totalCost // The total cost
    OUTPUT "The cost per person for this trip is $", costPerPerson // The cost per person
    OUTPUT "THe total amount collected is $", totalAmountCollected // amount of money collected by organiser