What does this line of C ++

C ++ beginners course: Chapter 3: Variables

int page;

This line initializes the variable 'page' as an integer so that the computer knows you and can use you.
Incidentally, a variable can also be assigned a value without any input by the user:


This would set the variable 'page' to 10.

Incidentally, all other types of variables are initialized in exactly the same way:

1

cout << "\ n" << endl;

The cout line is already known from Chapter 2. But something has changed. And what does this '\ n' mean?
Quite simply, for the sake of clarity, I have written the text output over several lines. \ n is for a line break.
<< endl; works as a line break, but it would be very cumbersome to append it to the end of each line.
You can end the text output like this and still have a line break:

1

cin >> page;

Now the user can assign a value to the variable 'page' using the keyboard. All you have to do is enter a number and hit enter. Finished.

page * page

In this line the square of 'side' is calculated, but how exactly? Look at the line again:


1

I deliberately pulled the individual parts apart a bit so that you can see what is responsible for what.
With "and << you can interrupt a text output and use the variable.
With side * side, as in mathematics, you simply calculate the square by inserting the operator in between.
And with << and "you start the text output again.

Task for chapter 3

After the third chapter of the introductory course, you should also be able to work on tasks independently. So here's a little exercise:

 

Write a program that asks the user to enter their first name. The program should then address the user by their first name and prompt the user to enter their age. The year of birth should then be calculated from the age and output with the name.

 

Hints: Simply insert the current year manually, as you do not know how to determine it otherwise. Be sure to write this line at the beginning of your program for the required string:

#include

 

A suggested solution to this task can be downloaded at the bottom of this page. If you solved the problem correctly, you are ready for Chapter 4.