Writing Pseudocode for Program Design | Programming in C

UPI Study › Courses › Programming in C › Free lessons › Lesson 1.4 Free with a free account

Writing Pseudocode for Program Design

Programming in C · Chapter 1: Programming Fundamentals, Pseudocode, and Program DevelopmentSection 1.4 · lesson 4 of 788 min · free with a free account

← Programming Logic and SyntaxNext lesson: Algorithm Design Principles →

Earn 3 college credits for Programming in CRecommended for credit by NCCRS · Computer Science 240 · self-paced · one payment, lifetime access

In this lesson

Plan programs in plain words, refine them and desk-check them.

  • Write pseudocode with the INPUT, SET, DISPLAY, IF and WHILE keywords
  • Apply stepwise refinement to turn vague steps into exact ones
  • Desk-check a plan by hand, including edge cases
  • Translate pseudocode into C and compare it with a flowchart

Free study notes

Get this lesson's notes by email

The key points and 4 practice questions with answers, in your inbox. One email, free.

One email. Unsubscribe in one click.

Transcript

Everything said in the video, section by section (1,129 words). Read along, or search it.

Opening Idea

Draw the Plan Before Building

Nobody builds a house by pouring concrete and hoping. First comes a drawing on paper, where moving a wall costs nothing but an eraser. Programmers have their own version of that drawing. Before Priya, who writes the arcade's software, types a single line of C, she writes the plan in careful, plain words. That habit saves her hours of fixing later. So what does a good plan look like, and how does it turn into code?

Definition

A Plan in Plain Words

That plan is called pseudocode: a step-by-step description of a program, in plain words, for people to read. Pseudo means pretend. It looks a bit like a program, but no computer runs it, and no compiler checks it. That freedom is the point. You think only about the logic, what should happen and in what order, without worrying about semicolons and braces. Anyone can read it, including Sam, who tests the software and doesn't need C to spot a missing step. And the same plan could later become C, Python, or anything else.

Why It Pays

Mistakes Are Cheaper on Paper

Pseudocode sits between the problem and the code. A mistake caught on paper is fixed with a few words. The same mistake caught after coding means hunting, editing, and compiling again.

Conventions

Five Capitalized Keywords

Because no compiler checks it, there's no single official way to write pseudocode. Programmers follow conventions: habits most people agree on. These lessons use five keywords in capitals. INPUT gets a value from the user. SET, TO, stores a value in a named box. DISPLAY shows something on the screen. IF, THEN, with ELSE and END IF, does some steps only when a condition is true. And WHILE, with END WHILE, repeats steps while a condition stays true.

Writing Habits

One Action Per Line, Indented

Around those keywords, four habits do most of the work. Write one action per line. Indent the steps that belong inside an IF or a WHILE, so the shape of the plan shows at a glance. Use meaningful names, like dollars and tokens, never d or x. And leave out every language detail: no semicolons, no braces, no printf.

Good and Bad Examples

Too Vague or Too Much Like C

Here are three versions of one plan. Too vague: get the money, do the tokens, maybe add a bonus. Nobody could code that. Too much like C: scanf, t equals d times four, and so on. Only a C programmer can read it, and d and t say nothing about their job. Good pseudocode sits in the middle: exact enough to code from, and plain enough for anyone to check. And watch for the common mistake both ways. If your plan has semicolons or percent d in it, you're already coding. If a line says handle it, ask: how, exactly?

Stepwise Refinement

Breaking Down the Bonus Rule

Now a real request from the arcade's owner. Every dollar buys four tokens. A player who spends ten dollars or more gets five bonus tokens on top. Priya's first draft is three lines: input dollars, work out the tokens, display dollars and tokens. The middle line is too vague to code. So she breaks it into smaller, exact steps. Replacing a big, fuzzy step with smaller precise ones, again and again until every line is clear, is called stepwise refinement. Set tokens to dollars times four. If dollars is ten or more, then set tokens to tokens plus five, indented. End if. Then display. Now every line is exact enough to code.

Desk Check

Tracing Nine, Ten and Twelve Dollars

Before any C exists, Sam checks the plan with a desk check: he walks through the steps by hand with sample inputs, and writes down every value. Nine dollars: thirty-six tokens. Is nine ten or more? No, so line four is skipped. Thirty-six. Ten dollars: forty tokens, then yes, so line four runs: forty-five. Twelve dollars: forty-eight, then yes: fifty-three. Line four is indented, so it runs only when the answer on line three is yes.

Edge Case

More Than Ten Versus Ten or More

Priya's first refined plan said: IF dollars is more than ten. Sam always tests the exact edge of a rule, so he desk-checked ten dollars. Forty tokens, no bonus. But the owner said ten dollars or more, so the answer should be forty-five. Priya changed three words on paper, and the bug was gone, before it ever reached C. So always test the edges: for ten or more, try nine, ten, and something bigger.

Quick Check

Desk-Checking Fifteen Dollars

Quick check. A player puts fifteen dollars into the token changer. Desk-check the refined plan. How many tokens at the end: sixty, sixty-five, or seventy-five? Pause, and decide. Sixty-five. Fifteen times four is sixty, and fifteen is ten or more, so line four adds five. Sixty forgets the bonus. Seventy-five gives five bonus tokens for every dollar, but the plan adds five only once. Only sixty-five matches the plan.

Translation

Turning Each Plan Line Into C

With a checked plan, writing the C is mostly translation. Each pseudocode line becomes one or two lines of C, and C adds the grammar. INPUT becomes a prompt with printf, plus scanf. SET becomes tokens equals dollars times four. Is ten or more becomes greater than or equal to ten, inside an if. END IF becomes a closing brace, and DISPLAY becomes printf. Priya keeps each pseudocode line as a comment above its C. Run it: twelve dollars gives fifty-three, ten gives forty-five. Both match Sam's desk check.

Flowcharts

Shapes, Arrows and a Diamond

Some people think better in pictures. A flowchart draws the same plan as shapes joined by arrows, and each shape has one job. Start. Input dollars. Set tokens to dollars times four. Then a diamond asks the question: dollars ten or more? A diamond has two exits. Yes leads to the bonus step. No skips it. Both paths meet again before the total is shown, and then the flowchart ends. Pseudocode is quicker to write and easy to turn into code. A flowchart makes branching paths easy to see.

Quick Check

A Score That Ties the Record

Quick check. A new plan: if the score is more than the record, display NEW HIGH SCORE. Else, display try again. The record is eight twenty, and a player scores exactly eight twenty. What does the plan display? Pause, and decide. Try again. Eight twenty is not more than eight twenty, so the IF answers no, and the ELSE step runs. NEW HIGH SCORE would need a score above the record. And with an ELSE, one of the two lines always runs, so it never displays nothing.

Key Takeaways

Plan, Refine, Check, Translate

To sum up. Pseudocode is a plan in plain words: no compiler, just logic. Write one action per line, with capital keywords, indents, and meaningful names. Refine fuzzy steps until each is exact, then desk-check by hand, especially at the edges. Then translate line by line into C, or draw it as a flowchart.

Think About It

Pseudocode for a Gold Badge

Something to think about. The arcade wants a rule: a player who scores over nine hundred on a birthday gets a gold badge. Write it in pseudocode with the five keywords. Which inputs will you desk-check, so that every edge is tested?

About Programming in C at UPI Study

Programming in C (Computer Science 240) is a self-paced online course of 78 video lessons in 11 chapters, from pseudocode and your first program to data types, decisions, loops, functions, arrays, strings, pointers, files, structures, dynamic memory and linked lists. It carries a NCCRS credit recommendation for 3 semester credits.

Every lesson transcript is free on pages like this one, and the videos are free with a free UPI Study account. Enrolling adds a practice quiz after each lesson, the graded work and final exam that earn the credit, lifetime access, and an official transcript on completion. UPI Study has helped over 130,000 students with college credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Compare: C vs C++

Why take it here

Why students take Programming in C with UPI Study

How programs work close to the machineProgramming in C teaches how a program uses memory: variables and data types, control flow, functions, arrays and strings, pointers, files, structures and dynamic memory. C is the base for operating systems, embedded devices and many computer-science courses.
Credit at a fraction of the priceThe same 3 credits can cost $750 or more at a US college. Here it is one payment, self-paced, with lifetime access.
Finish your degree soonerTransfer credits reduce the courses you still owe, so you can graduate earlier or lighten a heavy semester.
Strengthen an applicationA completed college-level course on an official transcript shows admissions and scholarship committees you can do the work.
Study on your own scheduleNo start dates, no deadlines. Watch the lessons, practice, and take the final when you are ready.
130,000+students helped with college creditsACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Where the credit goes

Universities that work with NCCRS

Programming in C carries a NCCRS credit recommendation. These universities work with NCCRS; some are UPI Study's signed partners. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.

Find my college → Not listed? Ask Athena in the corner of this page, or book a 15-minute call.

FAQ

Questions students ask us

About Writing Pseudocode for Program Design

What is pseudocode and why do programmers write it?
Pseudocode is a step-by-step description of a program in plain words, written for people rather than computers. No compiler checks it, so the writer can focus on what should happen and in what order without worrying about semicolons or braces. A mistake found on paper costs a few words to fix. A checked plan can then be translated into C, Python or another language.
What is stepwise refinement?
Stepwise refinement means replacing a vague step with smaller, exact steps, again and again, until every line is clear enough to code. For example, work out the tokens becomes set tokens to dollars times four, followed by if dollars is ten or more, set tokens to tokens plus five. Each refined line should describe one action that turns into one or two lines of code.
What is a desk check in programming?
A desk check is tracing a plan or program by hand with sample inputs and writing down every value as it changes. It catches logic mistakes before any code exists. For a rule of four tokens per dollar plus five bonus tokens at ten dollars or more, nine dollars gives 36 tokens and ten dollars gives 45. Testing the exact edge of each rule matters most.
What is the difference between pseudocode and a flowchart?
Pseudocode describes a plan in written lines, while a flowchart draws the same plan as shapes joined by arrows. In a flowchart, a diamond holds a yes-or-no question and has two exits, so branching paths are easy to see. Pseudocode is quicker to write and easier to turn into code line by line. Both describe the logic, not the syntax of a particular language.

About the Programming in C course

How many college credits is Programming in C?
Programming in C (Computer Science 240) carries a NCCRS credit recommendation for 3 semester credits. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities.
How much does Programming in C cost and what is included?
$250, paid once, with lifetime access: all 78 video lessons, a practice quiz after each, the graded work and final exam, and an official transcript when you finish. Students who want several courses choose UPI Study PRO instead.
Which universities accept UPI Study credits?
UPI Study has signed partner agreements with universities such as Thomas Edison State University, University of the People and Charter Oak State College, and works with universities such as Penn State, SNHU and SUNY. ACE and NCCRS have over 2,100 cooperating colleges that will consider accepting credits; the final decision is with the universities. Use "Find my college" on this page to check yours.
How long does Programming in C take?
It is self-paced with no deadlines. The 78 lessons total about 9 hours of video; most students add reading and practice time and finish in a few weeks to a few months, on their own schedule.
How are the exams done?
Quizzes and assignments are online in the course. The final exam is taken online with proctoring; a person on the UPI Study team checks assignments, usually within two days.
How do my credits reach my college?
When the course shows 100% complete, request the official transcript from your dashboard. It is sent to the college you name, and you can send it to more than one. Check your college first with "Find my college" on this page, or ask Athena.

Ready for the full course? Earn 3 credits in Programming in C.

78 video lessons, a quiz after each one, and the graded work that earns the credit. Recommended for credit by NCCRS.

Programming in C
3 credits · NCCRS
Enroll →