Input from User in C++

User input in C++ programming are used to take input from user, scanf() is one of the commonly used function to take input from user and proceed with that value.

Program Working with getch Function

Program

#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"Please Enter any Key to Continue"<<endl;
getch(); //waiting for get character 'user enter key'.
cout<<"Please Enter any Key to clear screen"<<endl;
getch(); //waiting for get character 'user enter key'.
clrscr();
cout<<"Please Enter any Key to Exit";
 getch(); //waiting for get character 'user enter key'.
}
Output
Please Enter any Key to Continue
Please Enter any Key to clear screen

Program User Entered value Printing

Program

#include<iostream.h>
#include<conio.h>
void main()
{
int num;
cout<<"Enter a number: ";
cin>>num; //user enter integer value storing in 'num' and
cout<<"You have just entered the number: "<<num; //printing 'num' value.
getch();
}
Output
Enter a number: 6
You have just entered the number: 6

Program Adding User Entered Values and Printing

Program

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,c;
cout<<"Please Enter First Integer"<<endl;
cin>>a; //user enter Integer value storing in 'a'.
cout<<"Please Enter 2nd Integer"<<endl;
cin>>b; //user enter Integer value storing in 'b'.
 c = a + b;
cout<<"The Answer is: "<<c; //printing 'c' value.
getch();
}
Output
Please Enter First Integer
5
Please Enter 2nd Integer
6
The Answer is: 11

Program Assigning Values to Variables and Printing
Program

#include<iostream.h>
#include<conio.h>
void main()
{
    //assigning values to variables.
int integerVar = 100;
float floatingVar = 331.79;
double doubleVar = 8.44e+11;
char charVar = 'W';
      //printing Variables values.
cout<<"integerVar = "<<integerVar<<endl;
cout<<"floatingVar = "<<floatingVar<<endl;
cout<<"doubleVar = "<<doubleVar<<endl;
cout<<"doubleVar = "<<doubleVar<<endl;
cout<<"charVar = "<<charVar;
getch();
}
Output
integerVar = 100
floatingVar = 331.79
doubleVar = 8.44e+11
doubleVar = 8.44e+11
charVar = W