Pseudocode is still somewhat confusing and I've been reading and this assignment for the a while now and I wanted to make sure I am understanding what's being asked of me. Could someone please tell me if my pseudocodes are correct?

Question:

1. Using pseudocode declare a Real number named temperature.

2. Using pseudocode declare a variable to store the Julian day (1-366) named JDay

3. Write pseudocode that asks a user to enter string variables to store a person’s lastname and birthdate. Then output the lastname and birthdate separated by a comma.


My pseudocode:

1. Declare temperature as double

2. Declare JDay as Integer

3. Declare LastName as string
Declare BirthDate as string
Write “Enter your last name”
Input LastName
Write “Enter your birthdate”
Input BirthDate
Set UserInfo = LastName = “ , “ + Birthdate

Dani AI

Generated

Your approach was essentially fine; the only real problem was the ambiguous assignment expression that pointed out and confirmed looked okay after the fix. A couple of short, practical tips will make the pseudocode clearer and more robust.

Pseudocode style: be consistent with naming, separate declaration from input/output, and show validation when the input has constraints. If you need to indicate numeric precision for a later implementation, say “use a double-precision floating type” rather than tying your pseudocode to a single language keyword — that keeps the intent clear across languages (C++ implementations typically prefer double for general-purpose decimals; see the C++ types reference below).

If the integer represents a day index within a year, validate it and handle leap years explicitly. Example pseudocode for leap-year detection and validating a day index:

Declare year as Integer
Declare dayOfYear as Integer

If ((year % 400 == 0) OR ((year % 4 == 0) AND (year % 100 != 0))) Then
    leap = true
Else
    leap = false
End If

maxDay = If leap Then 366 Else 365
If dayOfYear < 1 OR dayOfYear > maxDay Then
    Output "Invalid day number"
End If

For name and date input, decide whether the date is a free-form string or a parsed date type. If you might perform date math later, store it as a date object; otherwise a string is fine. Always trim and validate input and prefer output formatting to concatenation if you need localized formats. Example:

Loop until surname not empty
    Prompt and Input surname
End Loop

Prompt and Input dobString
Output Format("{0}, {1}", surname, dobString)

References:

Recommended Answers

All 3 Replies

>Set UserInfo = LastName = “ , “ + Birthdate
My brain has trouble parsing this line. Perhaps you meant:

Set UserInfo = LastName + “ , “ + Birthdate

I apologize, yes that's what I meant. Did you find any other issues with my pseudocode?

I apologize, yes that's what I meant. Did you find any other issues with my pseudocode?

Your code is good :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.