forked from ChicoState/MyFirstExample
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (33 loc) · 896 Bytes
/
Copy pathmain.cpp
File metadata and controls
40 lines (33 loc) · 896 Bytes
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
#include <iostream>
#include <cmath>
using std::cin;
using std::cout;
using std::endl;
// introduce a bad practice.
void test() {
int *p = new int;
}
void test1() {
int x;
x = 1;
}
int main() {
cout << "Hi, please enter two integers which we will add, divide and find the exponent of: ";
int num1, num2;
cin >> num1 >> num2;
// handle division by zero
while (num2 == 0) {
cout << "We cannot divide by zero, please enter a non-zero integer: ";
cin >> num2;
}
// print results
int result_add = num1 + num2;
int result_div = num1 / num2;
int result_exp = pow(num1, num2);
cout << num1 << " + " << num2 << " = " << result_add << endl;
cout << num1 << " / " << num2 << " = " << result_div << endl;
cout << num1 << "^" << num2 << " = " << result_exp << endl;
test(); // warn
test1(); // warn
return 0;
}