Lecture 2 - Taking User Input | C/C++ Video Tutorials and Lectures for Beginners

preview_player
Показать описание

Transcription
=============

We shall learn how to obtain an input from the user.
We shall ask the user to enter an int number for his age.
Then we shall store the input in a variable, and finally display it back to the monitor.
Write the usual code till the main function.
This statement prompts the user to enter a number for his age.
Next we create a variable to store the input from the user.
This statement reads the input from the monior and pushes it into our variable.
"cin" stands for console input.
So this statement reads the console input and stores the data into our variable.
The direction of the arrows indicates the direction in which the data moves.
The data is being streamed from the monitor towards the variable.
Here we are displaying the age entered by the user.
We haven't put age in double quotes because it is a variable.
If we put age in quotes it would be spelt back as plain english text.
There is another thing that needs to be seen here. We have chained the double arrows.
The double arrows pointing towards the left are called insertion operators.
While those pointing towards the right are called extraction operators.
It is possible to chain both the extraction and insertion operators.
But it is more common to chain the insertion operators as we have done.
Lastly, complete the function by writing the return statement.
This is how we can obtain user input using C++.
Thanks !
Рекомендации по теме
Комментарии
Автор

There are a couple of errors in the video. It should look like this:

#include <iostream>
using namespace std;
int main ()
{
cout << "Enter your age: ";

int age;

cin >> age;

cout << "Your age is " << age;

return 0;
}

SerenityComplex
Автор

#include <iostream>

using namespace std;

int main()
{
cout << "enter your age" << endl;
// here you ask the user to enter his or her age

int age;
// here we declare the variable int, in this case age

cin >> age;
// this is your input on the keyboard, you type your age using your fingers and a keyboard in front of you

cout << " your age is: " << age << " years old " >> endl;
// self explanatory i hope


return 0;

Alien-dvxr
Автор

there is an error :cin>>age not i

houssemhouhou
Автор

errors in this video, if are just leartning from zero, please avoid at all cost this video

Alien-dvxr
join shbcf.ru