Home Taking input from user
Post
Cancel

Taking input from user

Today we will learn how to take input from user in C++.We will do this using cin in iostream library.cin takes input from keyboard and stores it in a variable like num.\n is used for going to next line so that output looks nice.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
using namespace std;
int main()
{
   int num;
   char ch;
   cout<<"enter number:\n";
   cin>>num;
   cout<<"enter character:\n";
   cin>>ch;
   cout<<"number="<<num<<"\n";
   cout<<"character="<<ch;
   return 0;
}

OUTPUT:

output

This post is licensed under CC BY 4.0 by the author.

Trending Tags