-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariable.cpp
52 lines (35 loc) · 1.13 KB
/
variable.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main()
{
//init a variable
int userAge(30);
double pi(3.14);
bool iLoveProgramming(true);
char aSimpleLettrer('m');
//display a variable
cout << "ur age is : " << userAge << endl;
cout << "the letter is : " << aSimpleLettrer << endl;
cout << " is love programming is : " << iLoveProgramming << endl << endl;
//give 2 or more names to a variable
int myAge(29);
int& alsoMyAge(myAge);
cout << "I'm " << myAge << "old (variable)" << endl << endl;
cout << "I'm " << alsoMyAge << "old (ref to the variable)" << endl;
//cin
string userName;
cout << "what's your name ?" << endl;
//cin >> userName; will catch the first world only
getline(cin, userName);//using get line to catch all char from the user
cout << "your name is " << userName << endl;
//init a const variable
int const myAgeToday(29);
string const myName("Max");
//use cmath example
int result = 16;
int newResult = sqrt(result);
cout << "sqrt of 16 : " << newResult << endl;
return 0;
}