Professional Documents
Culture Documents
LESSON 5 InputOutput
LESSON 5 InputOutput
BASIC
INPUT/OUTPUT
BSMATH-1A
May 13, 2024
Prepared by:
4
C++ Output
5
Example 1: String Output
int main() {
// prints the string enclosed in double quotes
cout << "This is C++ Programming";
return 0;
}
6
Note: If we don't include the using namespace std; statement, we need to
use std::cout instead of cout.
This is the preferred method as using the std namespace can create
potential problems.
#include <iostream>
int main() {
// prints the string enclosed in double quotes
std::cout << "This is C++ Programming";
return 0;
}
7
Example 2: Numbers and Characters Output
#include <iostream>
using namespace std;
Output:
int main() { 70
int num1 = 70; 256.783
double num2 = 256.783; character: A
char ch = 'A';
9
C++ Input
10
Example 3: Integer Input/Output
#include <iostream>
using namespace std; Output
12
C++ Taking Multiple Inputs
#include <iostream>
Output
using namespace std;
Enter a character and an integer:
int main() { F
char a; 23
int num; Character: F
Number: 23
cout << "Enter a character and an integer: ";
cin >> a >> num;
return 0;
} 13
THANK YOU!
Any questions?
Prepared by:
Instructor I