-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput-output.cpp
More file actions
31 lines (25 loc) · 1.18 KB
/
input-output.cpp
File metadata and controls
31 lines (25 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
using namespace std;
int main(){
string a; //only takes one word(without get line).
cout<<"ENTER sentence: ";
//use the getline() function to read a line of text. It takes cin as the first parameter, and the string variable as second.
//cin considers a space (whitespace, tabs, etc) as a terminating character, which means that it can only store a single word (even if you type many words).
getline(cin,a); //takes the whole line of input.
cout<<"Entered sentence: "<<a<<endl;
int b; //integer value without decimal points.
cout<<"Enter a integer: "; //displays what is written inside "".
cin>>b; //inputs or stores the value to the given variable.
cout<<"Entered integer: "<<b<<endl; //endl makes the cursor jump down from the present position.
char c;
cout<<"Enter a char: "; //only takes one letter
cin>>c;
cout<<"Entered char "<<c<<" is valid."<<endl;
float d; //float value ex:123.67
cout<<"Enter a float value: "; //only takes float value.
cin>>d;
cout<<"Entered float "<<d<<" is valid.";
//defining a constant.
const float pi=3.14;
return 0; //incidates that the program has ended.
}