Sentinel value in while loop not working.

Let me start off by saying that this is my first time posting on here and any and all help will be greatly appreciated!!

I have a while loop that is reading in a value from a file and is suppose to stop looping when it gets to negative value. It does stop looping when it gets to a negative but it still displays the negative value in my output.

Basically what im trying to do is make it stop looping and NOT display the negative value when it reaches it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
while ( salesman_ID >= 0 )
    { 
         //readData is the function that is reading in the values from a file.

         readData ( fin, salesman_ID, monthly_sales_figure, count ); 
         
         //all the rest below are just functions for the mathematics portion.

         calcCommission ( commission, monthly_sales_figure, COMMISSION_RATE, 
                          TARGET_SALES_AMOUNT, met_goal );
                          
         calcBonus ( bonus, monthly_sales_figure, TARGET_SALES_AMOUNT, 
                     BONUS_RATE );
                     
         calcEarnings ( total_earnings, commission, bonus );
         
         printReport ( fout, salesman_ID, monthly_sales_figure, 
                     commission, bonus, total_earnings, met_goal);
         
     }


Anything i can do to make it only display the positive values and stop looping once it hits a negative?
Thanks in advance!
-Erik
Set the loop condition to true and use an if statement after reading the value to break; before printing or doing anything else with the value.
worked perfect! thank you so much!
Topic archived. No new replies allowed.