Variables & Data Types

Master the fundamentals with 10 hands-on exercises

3 Easy 4 Medium 3 Hard ~60 min total
Related Lesson
Variables & Data Types Theory
1

Age Calculator

Easy 5 min

Problem:

Write a pseudocode algorithm that asks the user for their birth year and calculates their current age.

Requirements:

  • Prompt the user to enter their birth year
  • Calculate age using current year (2024)
  • Display the calculated age

Example Output:

Sample Run
Enter your birth year: 1990 Your age is: 34 years old.
Need Help? Try These Hints First!

Solution

Algorithm AgeCalculator
    var currentYear = 2024
    var birthYear = Input "Enter your birth year:"
    var age = currentYear - birthYear
    Print "Your age is:", age, "years old."
Endalgorithm
Key Concepts:
  • Variables store data
  • Input keyword gets user data
  • Arithmetic operators perform calculations
  • Print keyword displays output
2

Rectangle Area

Easy 5 min

Problem:

Write a pseudocode algorithm to calculate the area of a rectangle given its length and width.

Requirements:

  • Prompt the user to enter the length
  • Prompt the user to enter the width
  • Calculate the area (length × width)
  • Display the calculated area

Example Output:

Sample Run
Enter length: 10 Enter width: 5 The area of the rectangle is: 50
Need Help? Try These Hints First!

Solution

Algorithm RectangleAreaCalculator
    var length = Input "Enter length:"
    var width = Input "Enter width:"
    var area = length * width
    Print "The area of the rectangle is:", area
Endalgorithm
Key Concepts:
  • Variables store numerical values
  • Multiplication operator (*) for area calculation
  • Input and Output operations are fundamental
3

String Concatenation

Easy 5 min

Problem:

Ask the user for their first name and last name, then combine them to display their full name.

Requirements:

  • Get first name from user
  • Get last name from user
  • Combine them with a space in between
  • Display the full name

Example Output:

Sample Run
Enter first name: John Enter last name: Doe Your full name is: John Doe
Need Help? Try These Hints First!

Solution

Algorithm FullNameGenerator
    var firstName = Input "Enter first name:"
    var lastName = Input "Enter last name:"
    var fullName = firstName + " " + lastName
    Print "Your full name is:", fullName
Endalgorithm
Key Concepts:
  • String variables store text
  • The + operator can concatenate (join) strings
  • Literal strings (like " ") are used for fixed text
4

Temperature Converter

Medium 7 min

Problem:

Convert a temperature from Celsius to Fahrenheit using the formula: F = C × 9/5 + 32

Example Output:

Sample Run
Enter temperature in Celsius: 25 25 Celsius is 77 Fahrenheit
Need Help? Try These Hints First!

Solution

Algorithm CelsiusToFahrenheit
    var celsius = Input "Enter temperature in Celsius:"
    var fahrenheit = (celsius * 9 / 5) + 32
    Print celsius, "Celsius is", fahrenheit, "Fahrenheit"
Endalgorithm
5

Shopping Bill Calculator

Medium 8 min

Problem:

Calculate the total bill for two items, including a 10% sales tax.

Example Output:

Sample Run
Enter price of item 1: 20 Enter price of item 2: 30 Subtotal: 50.0 Tax (10%): 5.0 Total Bill: 55.0
Need Help? Try These Hints First!

Solution

Algorithm ShoppingBill
    var price1 = Input "Enter price of item 1:"
    var price2 = Input "Enter price of item 2:"
    var subtotal = price1 + price2
    var taxAmount = subtotal * 0.10
    var totalBill = subtotal + taxAmount
    Print "Subtotal:", subtotal
    Print "Tax (10%):", taxAmount
    Print "Total Bill:", totalBill
Endalgorithm
6

Time Converter

Medium 8 min

Problem:

Convert a given number of days into years, weeks, and remaining days (365 days/year, 7 days/week).

Example Output:

Sample Run
Enter total days: 400 400 days is: 1 Year 5 Weeks 0 Days
Need Help? Try These Hints First!

Solution

Algorithm TimeBreakdown
    var totalDays = Input "Enter total days:"
    
    var years = totalDays / 365
    var remainingDays = totalDays mod 365
    
    var weeks = remainingDays / 7
    var finalDays = remainingDays mod 7
    
    Print totalDays, "days is:"
    Print years, "Year"
    Print weeks, "Weeks"
    Print finalDays, "Days"
Endalgorithm
Key Concepts:
  • Integer division (/) for whole units
  • Modulo operator (mod) for remainders
  • Sequential calculations
7

BMI Calculator

Hard 10 min

Problem:

Calculate the Body Mass Index (BMI) given weight in kilograms and height in meters. Formula: BMI = weight / (height × height)

Example Output:

Sample Run
Enter weight in kg: 70 Enter height in meters: 1.75 Your BMI is: 22.86
Need Help? Try These Hints First!

Solution

Algorithm BMICalculator
    var weightKg = Input "Enter weight in kg:"
    var heightMeters = Input "Enter height in meters:"
    
    var bmi = weightKg / (heightMeters * heightMeters)
    Print "Your BMI is:", bmi
Endalgorithm
Key Concepts:
  • Exponentiation (squaring) using multiplication
  • Float variables for precise calculations
  • Order of operations with parentheses
8

Circle Properties

Medium 7 min

Problem:

Calculate both area and circumference of a circle given its radius (π = 3.14159).

Example Output:

Sample Run
Enter radius: 5 Circle Area: 78.53975 Circle Circumference: 31.4159
Need Help? Try These Hints First!

Solution

Algorithm CircleProperties
    var pi = 3.14159
    var radius = Input "Enter radius:"
    
    var area = pi * radius * radius
    var circumference = 2 * pi * radius
    
    Print "Circle Area:", area
    Print "Circle Circumference:", circumference
Endalgorithm
Key Concepts:
  • Constants (like π) stored in variables
  • Mathematical formulas in pseudocode
  • Squaring by multiplying number by itself
9

Currency Exchange

Hard 10 min

Problem:

Convert USD to EUR, GBP, and JPY with proper formatting (1 USD = 0.85 EUR, 0.73 GBP, 110.50 JPY).

Example Output:

Sample Run
Enter amount in USD: 100 $100.00 USD equals: €85.00 EUR £73.00 GBP ¥11050.00 JPY
Need Help? Try These Hints First!

Solution

Algorithm CurrencyExchange
    var usdToEur = 0.85
    var usdToGbp = 0.73
    var usdToJpy = 110.50
    
    var usdAmount = Input "Enter amount in USD:"
    
    var eurAmount = usdAmount * usdToEur
    var gbpAmount = usdAmount * usdToGbp
    var jpyAmount = usdAmount * usdToJpy
    
    Print "$", usdAmount, "USD equals:"
    Print "€", eurAmount, "EUR"
    Print "£", gbpAmount, "GBP"
    Print "¥", jpyAmount, "JPY"
Endalgorithm
Key Concepts:
  • Multiple related constants
  • One input for multiple calculations
  • Currency symbols for user-friendly output
10

Student Grade Average

Hard 12 min

Problem:

Calculate a student's final grade average from 5 test scores and determine pass/fail status (average >= 60).

Example Output:

Sample Run
Enter test 1 score: 85 Enter test 2 score: 92 Enter test 3 score: 78 Enter test 4 score: 88 Enter test 5 score: 95 ---Student Report--- Test Scores: 85, 92, 78, 88, 95 Total: 438 Average: 87.6 Status: Pass
Need Help? Try These Hints First!

Solution

Algorithm StudentGradeAverage
    var test1 = Input "Enter test 1 score:"
    var test2 = Input "Enter test 2 score:"
    var test3 = Input "Enter test 3 score:"
    var test4 = Input "Enter test 4 score:"
    var test5 = Input "Enter test 5 score:"
    
    var total = test1 + test2 + test3 + test4 + test5
    var average = total / 5
    
    var status = "Fail"
    If average >= 60 Then
        status = "Pass"
    Endif
    
    Print "---Student Report---"
    Print "Test Scores:", test1, ",", test2, ",", test3, ",", test4, ",", test5
    Print "Total:", total
    Print "Average:", average
    Print "Status:", status
Endalgorithm
Key Concepts:
  • Multiple related variables (test1, test2, etc.)
  • Accumulating values for totals
  • Average calculation: sum ÷ count
  • Comparison operators (>=) for conditions
Back to Exercise Hub