include iostream using namespace std union point int decimal double _f

 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
#include <iostream>
using namespace std;
union point {
int decimal;
double _float;
void init() {
cin >> _float;
if ((int) _float == _float) {
decimal = (int) _float;
}
}
double get() {
if (_float != NULL) return _float;
return decimal;
}
};
struct points {
point value;
};
void insert(points &point){
cout << "Input x: ";
point.value.init();
}
int main() {
struct points x;
insert(x);
cout << "x = " << x.value.get() << ";";
}