-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path02_user-input.cpp
More file actions
20 lines (18 loc) · 1008 Bytes
/
02_user-input.cpp
File metadata and controls
20 lines (18 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//This is a program to get an input from user and print it
#include <iostream>
using namespace std; //thse two lines are common and required in all teh programs
int main() {
int a; //defining that input a is an integer
char b; //defining that input b is a character
string c; //defining that input c is a string
cout << "Enter a number : "; //printing a message requesting to enter an input
cin >>a; //assigning the input value to a
cout << "Enter an alphabet : "; //printing a message requesting to enter an input
cin >>b; //assigning the input value to b
cout << "Enter a text : ";
getline (cin, c); //use getline to read input having more than one character
cin >> c; //assigning the input value to c
cout << "You entered the number : " << a <<endl; //printing the output with the input value
cout << "You entered the alphabet : " <<b <<endl; //printing the output with the input value
cout << "You entered the text : " <<c <<endl; //printing the output with the input value
}