C++ Program to Read an Integer and Character and Print on Screen

  • Write a program in C++ to read a character and Integer from user and print on screen.
  • How to read integer and character in C++ programming language.

C++ program to read and print an integer and character

In this program, we will take an integer and character as input from user using cin stream and print it on screen using cout. This program helps in understanding basic input and output of C++ programming language.

/*
C++ program to read a number and a character fron user 
and print it on screen
*/
#include <iostream>

using namespace std;

int main() {
    int val;
    char c;
    // Read input 
    cout << "Enter an Integer and a Character\n";
    cin >> val >> c;
    // Print on screen
    cout << "Entered Integer : " << val << endl;
    cout << "Entered Character : " << c;
    
    return 0;
}
Output
Enter an Integer and a Character
12 A
Entered Integer : 12
Entered Character : A