Can u help me with the code below, idea is to sum the numbers in range of brKarika
lets say br Karika =4 and numbers are:
3 11 4 7
so
suma[1]=3+13
suma[2]=3+13+4
suma[3]=3+11+4+7
1 2 3 4 5 6 7 8 9 10 11 12
int brKarika;
cout << "Unesi broj karika u pronadenom lancu" << endl;
cin >> brKarika;
vector<int> suma;
suma.resize(brKarika);
for (int i=0; i<brKarika; i++)
{
cin >> karika;
suma[i] = (i == 0) ? karika : suma[i-1] + karika; // kumulativno zbrajamo cvrstoce
}
suma[i] = (i == 0) -> this part is confusing me, can somebody explain it to me
for karika values inputed we check if value suma of indx i is equal to ??, cuz i==0 wil return true in first step, but suma[0] can be any number, help needed please guys.
ok then in my case test expression is suma[i]=(i==0)
i still dont understand expression?? that is why i asked in first place, i get how conditional operator works, but dont get how this expression does?
that is what i wanted to know, i've checked the link and my mind started to understand :)
after that i returned here and saw your post with the same link :)
cuz actually i will stick to writing if conditions, sometimes conditional operotor and it sintax confuses me