@@ -19,7 +19,7 @@ int main() {
19
19
int num1 {200 };
20
20
int num2 {100 };
21
21
22
- // cout << num1 << " + " << num2 << " = "<< num1+ num2 << endl;
22
+ cout << num1 << " + " << num2 << " = " << num1+ num2 << endl;
23
23
24
24
int result {0 };
25
25
@@ -37,21 +37,32 @@ int main() {
37
37
38
38
result = num2 / num1;
39
39
cout << num2 << " / " << num1 << " = " << result << endl;
40
-
40
+ // since we are working with integers the 5 in 0.5 will be chopped and only 0 is outputted
41
+ // use double instead of integer type
42
+
41
43
result = num1 % num2;
42
- cout << num1 << " % " << num2 << " = " << result << endl;
44
+ cout << num1 << " % " << num2 << " = " << result << endl;
45
+ // 200 divided by 100 = 2 with no reamainder, remainder = 0, result = 0
43
46
44
47
num1 = 10 ;
45
48
num2 = 3 ;
46
49
47
50
result = num1 % num2;
48
- cout << num1 << " % " << num2 << " = " << result << endl;
51
+ cout << num1 << " % " << num2 << " = " << result << endl;
52
+ // 10 divided by 3 = 9 with reaminader = 1, result = 1
49
53
50
- result = num1 * 10 + num2;
54
+ result = num1 * 10 + num2;
55
+ // compiler might read right to left but arithmetic operations still holds true
56
+ // num1 will be multiplied by 10 first, then add num2
57
+
58
+ // if one desire to multiply num1 by 10 + num2, then we need perentesis ()
59
+ result = num1 * (10 + num2);
51
60
52
61
cout << 5 /10 << endl;
62
+ // output 0 since 0.5 is not an integer, the 5 will be chopped
53
63
54
64
cout << 5.0 /10.0 << endl;
65
+ // output 0.5 since we are using double instead of integer with the .0
55
66
56
67
cout << endl;
57
68
return 0 ;
0 commit comments