Is sequence of mathematical operations in C++ is important? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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