-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalcTotal.jsx
98 lines (82 loc) · 2.79 KB
/
CalcTotal.jsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import React, { useState } from 'react';
import { View, Text, TextInput, StyleSheet} from 'react-native';
import { TouchableOpacity } from 'react-native';
export default function CalcTotal() {
const [operacoes, setOperacoes] = useState({
a: 0,
b: 0
});
const clean = () => {
setResult({
result: '',
})
};
const [result, setResult] = useState(0);
return (
<View>
<Text>O resultado é: {result}</Text>
<TextInput
style={css.input}
placeholder="Digite o valor A" onChangeText={(valor) => setOperacoes({
...operacoes, a: Number(valor)
})
} keyboardType="numeric"
/>
<TextInput
style={css.input}
placeholder="Digite o valor B" onChangeText={(valor) => setOperacoes({
...operacoes, b: Number(valor)
})
} keyboardType="numeric"
/>
<TouchableOpacity style={css.input}
onPress={() => setResult(operacoes.a + operacoes.b)}
>
<Text>+SOMA+</Text>
</TouchableOpacity>
<TouchableOpacity style={css.input}
onPress={() => setResult(operacoes.a - operacoes.b)}
>
<Text>-SUBTRAÇÃO-</Text>
</TouchableOpacity>
<TouchableOpacity style={css.input}
onPress={() => setResult(operacoes.a * operacoes.b)}
>
<Text>XMULTIPLICAÇÃOX</Text>
</TouchableOpacity>
<TouchableOpacity style={css.input}
onPress={() => setResult(operacoes.a / operacoes.b)}
>
<Text>/DIVISÃO/</Text>
</TouchableOpacity>
<TouchableOpacity style={css.input}
onPress={() => setResult(Math.pow(operacoes.a, operacoes.b))}
>
<Text>Exp a²b</Text>
</TouchableOpacity>
<TouchableOpacity style={css.input}
onPress={() => setResult(Math.pow(operacoes.a, 2))}
>
<Text>a²</Text>
</TouchableOpacity>
{/* <TouchableOpacity style={css.input}
onPress={() => setResult(operacoes.a % operacoes.b)}
>
<Text>Resto</Text>
</TouchableOpacity> */}
<TouchableOpacity style={css.input}
onPress={(clean) => setResult(operacoes.a = '', operacoes.b = '')}
>
<Text>AC-Clear</Text>
</TouchableOpacity>
</View>
)
}
const css = StyleSheet.create({
input: {
borderRadius: 10,
padding: 10,
borderWidth: 2,
fontSize: 20
}
})