-4

I'm just trying to do a simple arithmetic operation but it returns me the 0 value. Here's the code:

 main(){

 long Population_A, Population_B; 

 cin>>Population_A;
 cin>>Population_B;

 float Increase_A, Increase_B;

 Increase_A = (6*Population_A)/100; //Here is the problem because I receive 0.
 Increase_B = (3*Population_B)/100;

 }//main
  • 1
    Is Population_A greater than 16? – Carl Norum Mar 11 '15 at 20:53
  • 3
    You've posted code that won't compile, that even if it did compile wouldn't actually show any problem, and even if it could show any problem, you haven't provided the input your program needs to show that problem. –  Mar 11 '15 at 20:53
  • 1
    integer division has already been addressed here: http://stackoverflow.com/questions/3602827/what-is-the-behavior-of-integer-division-in-c – Aaron Iggy Sutter Mar 11 '15 at 21:00
  • @CarlNorum I figured out the problem. But why if Population_A is less than 16 will failed? – JoseMCabrera Mar 11 '15 at 21:06

1 Answers1

0

If Population_A is in the range -16 .. 16, the integer multiply and divide will result in 0.

If you want floating point division results rather than converting integer values to floats, change 6 to 6.0F and 3 to 3.0F.

Jerry101
  • 12,157
  • 5
  • 44
  • 63