Pseudocode to find a larger number between two numbers:
DECLARE num1, num2 : REAL
OUTPUT "Enter your first number: "
INPUT num1
OUTPUT "Enter your second number: "
INPUT num2
IF num1 > num2
OUTPUT "Your first number is greater than your second number!"
ELSE IF num1 < num2
OUTPUT "Your second number is greater than your first number!"
ELSE num1 = num2
OUTPUT "Both of the numbers are equal!"
END IF
Pseudocode to find if number is positive or negative:
DECLARE num1 : REAL
OUTPUT "Enter your number: "
INPUT num1
IF num1 > 0
OUTPUT "Your number is positive!"
ELSE IF num1 < 0
OUTPUT "Your number is negative!"
ELSE
OUTPUT "Your number is zero!"
END IF
Pseudocode to identify type of triangle based on side:
DECLARE length1, length2, length3 : REAL
OUTPUT "Write down the length of the first side of the triangle: "
INPUT length1
OUTPUT "Write down the length of the second side of the triangle: "
INPUT length2
OUTPUT "Write down the length of the third side of the triangle: "
INPUT length3
IF length1 = length2 AND length2 = length3
OUTPUT "Your triangle is equilateral!"
ELSE IF (length1 = length2 AND length1 != length3) OR (length1 = length3 AND length1 != length2)
OR (length1 = length3 AND length1 != length2) OR (length2 = length3 AND length2 != length1)
OUTPUT "Your triangle is isosceles!"
ELSE
OUTPUT "Your triangle is scalene!"
END IF
Pseudocode that identifies final price based on given percentage:
Book_Price = 25 //This is a constant!
DECLARE Sale : INTEGER
DECLARE Final_Price : REAL
// The person writes their percentage, for example 40%. It is converted to 0.4 and then calculated!
OUTPUT "What is the added sale in percentage value? "
INPUT Sale
Final_price = 25 + (25*(Sale/100))
OUTPUT "Your final price is ", Final_price
Pseudocode to find area and circumference of a circle based on radius:
Pi = 3.1416 // This is a constant!
DECLARE Radius, Area, Circumference : REAL
OUTPUT "Enter the radius of the circle!"
INPUT Radius
Area = Pi * Radius * Radius
Circumference = 2 * Pi * Radius
OUTPUT "The area of the circle is ", Area
OUTPUT "The circumference of the circle is", Circumference
Pseudocode for Week 11 – Task 3: Muffin Problem!
DECLARE NumMuffins INTEGER
DECLARE FinalPrice, DiscountedFinalPrice : REAL
OUTPUT "Enter the number of muffins ordered!"
INPUT NumMuffins
FinalPrice = NumMuffins * 2
DiscountedFinalPrice = NumMuffins * 2 - (0.2 * NumMuffins * 2)
// We also could have done 0.8 * NumMuffins * 2
IF NumMuffins <= 5
OUTPUT "Your final price is", FinalPrice
ELSE
OUTPUT "Your final price due to discount is", DiscountedFinalPrice
ENDIF
Programming Construct: Determines the order in which lines of code are executed.
Types:
Sequence: Do things one by one in a sequence.
Selection: If statement, where on thing is done under one condition. It is a decision or question.
Repetition: Do the same things multiple times like a for loop.
Types of selection:
IF..THEN..ENDIF
IF..THEN..ELSE..ENDIF
Whole number: Integer
Any number: Real
Single letter: Char
Many letters: String
Conditional: True/False