# help with some maths

so i have my gun with a clipsize of 30
my inventory has say a spare 30 bullets for me to use when reloading
i fire some bullets and no my guns current ammo is 12
when i reload it takes the bullets from the inventory and works out how much to give the current ammo in this case its 18
now when i have less than 30 ammo in the inventory so say i have 18 bullets in the inventory and 27 in the clip when i reload using the logic i have now it will just add it all up into the clip creating a larger number than the clip size. what can i add to make sure it only adds until the clipsize this is that i have so far

``````int ammoToTake = weaponStats.ClipSize - weaponStats.CurrentAmmo;
if (weaponStats.CurrentAmmo < weaponStats.ClipSize){
if (weaponStats.CurrentAmmo < inven.Items*.itemValue)*
``````
• `````` 				{*
``````
• `````` 						weaponStats.CurrentAmmo += ammoToTake;*
``````

_ inven.Items*.itemValue -= ammoToTake;_
_
}_
_
}*_

I think what you are really try to say is:

``````if ( ammoToTake > inven.Items*.itemValue ) {*
``````

ammoToTake = inven.Items*.itemValue;*
}

So, in full, I think you mean this:
int ammoToTake = weaponStats.ClipSize - weaponStats.CurrentAmmo;

if (weaponStats.CurrentAmmo < weaponStats.ClipSize){

if ( ammoToTake > inven.Items*.itemValue ) {*
ammoToTake = inven.Items*.itemValue;*
}

weaponStats.CurrentAmmo += ammoToTake;
inven.Items*.itemValue -=ammoToTake;*

}