Core Program Structure: Input, Processing, and Output

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

Core Program Structure: Input, Processing, and Output

Programming in C · Chapter 1: Programming Fundamentals, Pseudocode, and Program DevelopmentSection 1.2 · lesson 2 of 787 min · free with a free account

← Understanding Programming FundamentalsNext lesson: Programming Logic and Syntax →

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

In this lesson

Every program takes input, processes it and produces output.

  • Identify the input, processing and output of a program
  • Recognize forms of input and output beyond the keyboard and screen
  • Explain how variables, scanf and printf fit the IPO model in C
  • Explain why input must come before processing and why input needs checking

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 (896 words). Read along, or search it.

Opening Example

Tickets In, a Prize Out

At the Starlight Arcade prize counter, you slide a stack of paper tickets across the desk. The clerk counts them, checks the prize wall, and hands you a yo-yo, plus a few tickets back. Three moments just happened. Something came in, something was worked out, and something came out. Almost every program ever written has that same shape, from a calculator to a giant online game.

The IPO Model

Input, Processing and Output

Those three jobs have names. The tickets you hand over are the input: information that goes into a program from outside. Counting them and choosing a prize is the processing: the work the program does with that information. The yo-yo and the leftover tickets are the output: the results that come back out. This shape is called the I P O model, short for input, processing, output. Information flows one way: in, worked on, out. Once you know it, you can ask three questions about any machine or app. What goes in? What does it work out? What comes out? Keep those three questions handy. They work on almost anything.

Four Examples

Same Shape, Different Processing

Try it on four very different programs. The token changer takes dollars, multiplies by four, and drops tokens into the tray. An arcade game takes the player's final score, compares it with the record, and shows NEW HIGH SCORE. A calculator takes two numbers and a plus sign, adds them, and shows the sum. A thermostat reads the room's temperature, asks whether it's below the setting, and turns the heater on or off. Input and output are what people notice. Processing is what makes each program different.

Input and Output Forms

Buttons, Sensors, Sounds and Files

Input isn't only typing. A press on a button, a coin rolling past a sensor, and a reading from a thermometer are all input. Output isn't only words on a screen. A sound, a flashing light, and a motor pushing out prize tickets are all output. One thing can sit on both sides: a saved high-score file. The game writes it tonight as output, and reads it back tomorrow as input. Your first C programs use the simplest pair. Input is what someone types on the keyboard. Output is text in the terminal window.

Processing

Calculating, Comparing and Sorting

Input and output are the parts people see. Processing is the hidden middle, and it's where the program earns its keep. Most processing is one of three kinds of work, often mixed. Calculating, like dollars times four. Comparing, like asking whether a score beats the record. And sorting, like putting a score table in order. To do any of it, the program must remember values while it runs. It keeps each one in a variable: a named box in memory that holds one value.

Worked Example

The Token Changer in C

Here's a real C program for the token changer, the middle of it. The gray words after two slashes are comments: notes for humans, which the compiler ignores. Each comment names the part that comes next. First two boxes, dollars and tokens. Then printf shows the question, how many dollars? That question is output. A message that asks for input is called a prompt. Then scanf waits until the player types a number and presses Enter, and puts it in the dollars box. That's the input. The line tokens equals dollars times four is the processing. In C, the asterisk means times. Finally, printf shows the answer, filling each percent d spot with a number, in order.

Running It

Five Dollars Buys Twenty Tokens

Run it, and type five. The five travels through the program: typed in, stored in the dollars box, multiplied, stored again, and shown. How many dollars? five. Five dollars buys twenty tokens.

Common Mistake

Processing Before the Input Arrives

A common mistake is putting the steps in the wrong order. A program runs from top to bottom. Move the processing line above scanf, and the program multiplies a number nobody has typed yet. A box never filled holds leftover junk. So the order is always the same: get the input, then process it, then show the output.

Testing Odd Input

Garbage In, Garbage Out

Sam, who tests the arcade's software, tries what a real player might do, including the odd things. He ran Priya's program and typed minus three. The program didn't complain at all. Minus three dollars buys minus twelve tokens. It did exactly what it was told. Programmers call this garbage in, garbage out: if the input makes no sense, the output won't either. The fix is more processing: a step that checks the input before using it. You'll add checks like that with decisions, later in the course.

Quick Check

Changing the Deal to Five Tokens

Quick check. The arcade changes its deal: every dollar now buys five tokens. Priya changes one line. Then a player types six. What does the last line say: thirty tokens, twenty-four tokens, or eleven tokens? Pause, and decide. Thirty tokens. Only the processing line changes, to dollars times five. Six times five is thirty. The input and output lines stay exactly as they were. Twenty-four is the old deal, and eleven adds the numbers instead of multiplying.

Key Takeaways

In, Worked On, Then Out

To sum up. Almost every program takes input, processes it, and produces output. Input and output come in many forms: buttons, sensors, files, sounds and lights. Processing calculates, compares and sorts, and keeps values in variables. And the order is fixed: input first, then processing, then output.

Think About It

What a Phone Alarm Saves

Something to think about. Take the alarm on your phone. What goes in, what does it work out, and what comes out? And is there anything it saves as output tonight, and reads back as input tomorrow?

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 Core Program Structure: Input, Processing, and Output

What is the IPO model in programming?
The IPO model describes a program as three stages: input, processing and output. Input is information coming in from outside, processing is the work the program does with it, and output is the result sent back out. A calculator, for example, takes two numbers and a plus sign, adds them, and shows the sum. Asking what goes in, what is worked out, and what comes out describes almost any program.
What does garbage in, garbage out mean?
Garbage in, garbage out means a program given nonsense input will produce nonsense output. A computer does exactly what it is told and does not judge whether the input makes sense. A token changer that multiplies dollars by four will report minus twelve tokens for minus three dollars. The fix is extra processing that checks the input before using it, such as rejecting negative amounts.
How do scanf and printf fit the input, processing and output stages in C?
In a simple C program, scanf handles input, an assignment does the processing, and printf produces the output. For example, scanf("%d", &dollars) stores a typed number, tokens = dollars * 4 calculates the result, and printf shows it by filling each %d with a value in order. A printf message that asks the user to type something is called a prompt.
Why does the order of input and processing statements matter in C?
Order matters because a C program runs from top to bottom, one statement at a time. If the calculation comes before scanf, the program uses a variable nobody has filled yet, and an uninitialized variable holds unpredictable leftover data. The safe order is to get the input first, then process it, then display the output, so every value exists before it is used.

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 →