2022 Jan P02 IT CSEC Q3a

Start
    // Initialization of variables....
    price = -999.99
    totalPrice = -999.99
    discountAmount = -999.99
    discountRate = 0.25
    quantity = -999
    
    // Prompt the user for input....
    output "Input Price"
    input price
    output "Input quantity"
    input quantity
    totalPrice = price * quantity
    
    // Determine the discount....
    if totalPrice > 1800 then
        discountAmount = totalPrice * discountRate
    else
        discountAmount = 0.00
    end If
    
    // output results....
    output "the Discount is " + discountAmount
Stop

Alternate solution

Note: In this solution , our selection statement does not contain an else branch, since the discountAmount is initialized to 0.

Start
    // Initialization of variables....
    price = -999.99
    totalPrice = -999.99
    
    // here, discount is set to 0.
    discountAmount = 0
    discountRate = 0.25
    quantity = -999
    
    // Prompt the user for input....
    output "Input Price"
    input price
    output "Input quantity"
    input quantity
    totalPrice = price * quantity
    
    // Determine the discount....
    if totalPrice > 1800 then
        discountAmount = totalPrice * discountRate
    else
        
        // because the discount was initialized to 0, we don't need an else section for our selection construct.
    end If
    
    // output results....
    output "the Discount is " + discountAmount
Stop

Additional resources

See flowcharts and solution in flowgorithm here:

https://drive.google.com/drive/folders/1pLQq5N6fqzs7wlFdUaehraZxkhGv2oke?usp=sharing

© 2022  Vedesh Kungebeharry. All rights reserved. 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s