Cherreads

Chapter 2 - Chapter 2 — The Curiosity of the Computer

The cursor blinked.

Slowly.

Patiently.

Like a tiny white heartbeat on the black screen.

_

Pran leaned closer to the monitor.

The room was quiet except for the soft humming sound of the computer fan. It sounded like the machine was breathing.

"Okay computer," Pran said. "We talked a little."

He crossed his arms.

"But now what?"

The cursor blinked again.

_

Still waiting.

Pran sighed.

"Well… I guess computers can't ask questions."

He paused.

Then he remembered something.

Computers can't ask questions unless you program them to.

"Alright," he said. "Let's try something."

He opened the program again and began typing.

#include

int main() {

printf("What is your name?\n");

return 0;

}

He ran the program.

The screen displayed:

What is your name?

Pran smiled.

"That's progress."

But there was a problem.

The computer asked a question… but it had no way to receive the answer.

That would be like asking someone their name and then immediately walking away.

Very rude.

And also not very useful.

Pran scratched his head.

"How do computers listen?"

He remembered reading about something called scanf.

If printf lets computers talk, then scanf lets computers listen.

He started typing again.

#include

int main() {

char name[50];

printf("What is your name?\n");

scanf("%s", name);

printf("Hello %s\n", name);

return 0;

}

He pressed run.

The program started.

What is your name?

Pran typed:

Pran

The computer responded:

Hello Pran

Pran jumped in his chair.

"WOAH!"

The computer had just used his answer.

It actually understood him.

Well… not really understood.

But it stored the information.

And that is incredibly powerful.

Let's break the code down.

First we created a variable.

char name[50];

This means:

Create a container that can store text.

Think of a variable like a box.

You give the box a name.

In this case, the box is called:

name

Inside the box we can store text like:

Pran

John

Alex

Maria

The [50] simply means the box can hold up to 50 characters.

Which is more than enough for most names unless someone is named something like:

Sir-Reginald-The-Third-Slayer-of-Dragons

Then the program might struggle.

But we'll worry about dragons later.

Next comes the line:

scanf("%s", name);

This tells the computer:

Wait for the user to type something and store it in the variable name.

The %s means string, which is programming language for text.

So when the user types something, the computer stores it.

Then we print it.

printf("Hello %s\n", name);

The %s inside printf is replaced with the value stored in the variable.

So if the variable contains:

Pran

The output becomes:

Hello Pran

Pretty cool, right?

Pran decided to experiment.

He ran the program again.

What is your name?

He typed:

Bob

The computer said:

Hello Bob

He ran it again.

What is your name?

This time he typed:

Pizza

The computer said:

Hello Pizza

Pran laughed.

"Alright… computers clearly trust humans too much."

He leaned back.

Programming suddenly felt less scary.

It wasn't about complicated math.

It was about instructions.

Clear instructions.

Computers are like extremely obedient assistants.

They will follow instructions perfectly.

Even if the instructions are silly.

Pran added another line.

printf("Nice to meet you!\n");

The program now looked like this:

#include

int main() {

char name[50];

printf("What is your name?\n");

scanf("%s", name);

printf("Hello %s\n", name);

printf("Nice to meet you!\n");

return 0;

}

He ran it again.

What is your name?

He typed:

Pran

The computer responded:

Hello Pran

Nice to meet you!

Pran nodded.

"Okay… that's actually friendly."

He imagined the computer as a polite robot sitting inside the screen.

A robot that could only communicate through C code.

The more code he wrote, the more the robot could do.

He wondered what else he could teach it.

Maybe it could ask more questions.

Maybe it could learn numbers.

Maybe it could even play games.

But for now, he wanted to try one more experiment.

He modified the program again.

#include

int main() {

char name[50];

printf("What is your name?\n");

scanf("%s", name);

printf("Hello %s\n", name);

printf("Welcome to the computer world!\n");

return 0;

}

He ran the program.

What is your name?

Pran typed slowly.

Pran

The computer printed:

Hello Pran

Welcome to the computer world!

Pran stared at the screen.

Something about that sentence felt… strange.

Welcome to the computer world.

The words lingered on the screen.

The cursor blinked again.

_

And then suddenly… another line appeared.

A line he did not write.

IDENTITY CONFIRMED

Pran froze.

"Wait… I didn't type that."

Another line appeared.

SYSTEM INTERACTION ENABLED

Pran leaned closer.

"Okay… that's definitely not my code."

Then the computer printed one more message.

NEXT TASK: VERIFY HUMAN AGE

Pran blinked.

The cursor blinked back.

The computer had spoken again.

And this time…

It wanted more information.

Pran cracked his knuckles.

"Well then," he said.

"Let's teach the computer about numbers."

Next chapter Preview

The Age Scanner, You'll learn:

int variables

scanf("%d")

storing numbers

printing numbers

More Chapters