0

Is sequence of mathematical operations in C++ is important?

Hello. Could you explain me why in my code mathematical operation " score = ( a / b ) * 100 " did not work and the code showed " score = 0 " ( the score should have been different), but when I changed sequence, " score = ( a * 100 ) / b ", it worked right. I used 'int' in every variables. Variables and score were positive and total. Thank you :)

13th Feb 2017, 8:39 PM
Arkadiusz
Arkadiusz - avatar
5 Answers
+ 4
yes the sequence is definetly important could you show us the code? btw: umiesz po polsku?😄
13th Feb 2017, 8:46 PM
Kamil
Kamil - avatar
+ 3
ok wiec: jeƛli liczysz a/b to musisz wiedzieć ĆŒe komputer trochę inaczej to traktuje niĆŒ się moĆŒe wydawać a i b = liczby typu int wiec nie zapisują zadnych liczb bo " , " a/b to 0,5 a 0,5 to nie int wiec zostaje zaokrąglone do liczby 0 ktĂłra moĆŒna bez problemu zapisać w int nastepnie to juĆŒ dziecinnie prosta matma 😀 0*100 to nadal 0 natomiast w 2 przypadku pierw liczysz * 100 a potem /b czyli /100 => zostaje tylko a mam nadzieje ze pomogƂem, jak coƛ to pisz tutaj😉 i sorry bo mĂłj polski trochę slaby😔
13th Feb 2017, 9:14 PM
Kamil
Kamil - avatar
0
Umiem 😀 #include <iostream> using namespace std; int main() { // variables int b = 100; int a = 50; int score; // counting of score score = (a / b ) * 100 ; // showing cout << score; return 0; }
13th Feb 2017, 9:02 PM
Arkadiusz
Arkadiusz - avatar
0
Dzięki za wytƂumaczenie Kamil, juĆŒ to zrozumiaƂem 😀
13th Feb 2017, 9:20 PM
Arkadiusz
Arkadiusz - avatar
0
Thanks for that
14th Feb 2017, 4:43 PM
hotpepper873