DEV Community

Mehfila A Parkkulthil
Mehfila A Parkkulthil

Posted on

Day 4: C++ language | Variables | Datatypes | Part-2

Please make sure to refer Day3: C++ language | Variables | Datatypes | Part-1


Topics to be covered

  • Variables
  • Declare multiple Variables
  • User Input

Variables

#include <iostream>
using namespace std;
int main(){
int age = 15;
cout << "my age is:" << age << endl ;

}
Enter fullscreen mode Exit fullscreen mode

Image

Image


Declare multiple variables

To declare more than one variable of the same type.

#include <iostream>
using namespace std;
int main(){

int x = 15, y = 6, z = 50;
cout << x + y + z;

}
Enter fullscreen mode Exit fullscreen mode

multiple variables

result

You can also assign the same value to multiple variables in one line.

#include <iostream>
using namespace std;

int main(){

int x, y, z;
x = y = z = 60;
cout << x + y + z;

}

Enter fullscreen mode Exit fullscreen mode

mul variables

Imagey


User input

In C++, the term "input" generally refers to the process of taking data from an external source (like the user or a file) and storing it in a variable for use in your program.

cin is a predefined variable that reads data from the keyboard with the extraction operator (>>) .

  • cout is pronounced "see-out". Used for output,and uses the insertion operator (<<)
  • cin is pronounced "see-in". Used for input, and uses the extraction operator (>>)

int z, y;
int sum;
cout << "Type a number: ";
cin >> z;
cout << "Type another number: ";
cin >> y;
sum = x + y;
cout << "Sum is: " << sum;


Here I gave two numbers 50 and 45 , it can be any according to that result varies.

Input

Input terminal

Input .v


Previous Blog

Top comments (0)