Cpp-User-Input-Learn-Cpp-Programming

In this chapter, we will learn C++ User Input – Learn C++ Programming. You have already learned that cout use to Output (print) value. and Now we will learn and use cin to get user input.

cin has a predefined object. so that can read data with the extraction operator >> from the keyboard.

In the following Example of C++, you will C++ Programming’s tool cin, and the user can input a number, which is store in the variable x. Then we print the value of variable x.

Example:

#include <iostream>
using namespace std;

int main(){
        int x;
        cout << "Type the value of X: ";
        cin >> x;
        cout << "The value of X is: ";
}

Output:

Type the value of X: 10
The value of X is: 10

Good To Know

cout is pronounced as See-out, and this use to output the value, with the insertion operator <<.
cin is pronounced as See-in, and this use to input the value, with the extraction operator >>.


Creating a Simple and good Calculator With C++

In this example, The user will input two number of value, and then we output the with calculation (adding) the two number, so, you also make your critical calculator with C++ with the using of Multiply(*), division(/) and instruction(-) operators.

Example:

#include <iostream>
using namespace std;

int main(){
        int x, y;
        int sum;
        cout << "Type the value of X: ";
        cin >> x;
        cout << "Type the value of Y: ";
        cin >> y;
        sum = x + y;
        cout << "Sum is: " << sum;
        return 0;
}

Output:

Type the value of X: 5
Type the value of Y: 20
Sum is : 25

So, The previous topic of Learn C++ Programming is:

Introduction to C++ Programming
So, read the full article to learn C++ and, basic concepts, If you read carefully, so you learn better.

Read all C++ Variables to learn about variables and then I Write a New chapter Comments in C++. So you learn it and the Next chapter is C++ Syntax. and also read it. So the next chapter is C++ Output (Print Text) and much read it completely.

By Usama Arshad

It's me Usama Arshad working as a Lecturer C++. I am a student of BSIT.

Leave a Reply

Your email address will not be published. Required fields are marked *