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 :)
5 Answers
+ 4
yes the sequence is definetly important
could you show us the code?
btw: umiesz po polsku?đ
+ 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đ
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;
}
0
DziÄki za wytĆumaczenie Kamil, juĆŒ to zrozumiaĆem đ
0
Thanks for that