Skip to content

Input and Output

Communication with users is essential in any program. Common Pseudocode provides simple statements for reading input and displaying output.

Display information to the user with the output statement:

output "Hello, World!"

Display variable values:

name = "Alice"
age = 30
output name
output age

Combine text and variables:

name = "Bob"
age = 25
output "Hello, my name is " name " and I am " age " years old"

Embed variables directly in strings using curly braces:

name = "Charlie"
score = 95
output "Player {name} scored {score} points!"
output "Welcome to the program!"
output "" // Empty line
output "Please select an option:"
output "1. Start"
output "2. Exit"

Read user input with the input statement:

input userInput

The value entered by the user is stored in the variable userInput.

It’s good practice to tell users what to enter:

output "What is your name? "
input userName
output "How old are you? "
input age
output "Enter your email: "
input userEmail

Here’s a full program that uses input and output:

// Greeting program
output "=== Welcome ==="
output ""
output "What is your name? "
input userName
output "What is your age? "
input userAge
output ""
output "Hello, {userName}!"
output "You are {userAge} years old."
// Calculate birth year (approximate)
currentYear = 2024
birthYear = currentYear - userAge
output "You were born around {birthYear}."

Creating an interactive menu:

output "Options: "
output "1. Book a ticket"
output "2. Cancel a ticket"
output "3. View a ticket"
output "4. View all tickets"
output "5. Track train"
output "6. Track all trains"
output "9. Exit"
output ""
output "Please enter an option: "
input userOption
  • Always provide clear prompts so users know what to enter
  • Use empty output statements (output "") to create blank lines for readability
  • When reading numbers, remember to convert string input to number if needed
  • Consider validating user input to handle errors gracefully
output "Enter a number: "
input userInput
number = convert userInput to number
if is number(number)
output "You entered: {number}"
else
output "That's not a valid number!"