You are loosing precision. For percentages you need to use floating points.
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
> p1 = w1/g2*100;
Should this be g1 ?
Also, try
p1 = w1 * 100 / g1;
to preserve the precision.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
1. Follow Salem's advice (better use p1 = (w1 * 100) / g1 ).
2. Change the last single % in the header string literal to double %% (see printf format string specifications).
3. Better use tabs \t to adjust columns in all trailing printfs.
ArkM
Postaholic
2,001 posts since Jul 2008
Reputation Points: 1,234
Solved Threads: 348
>>3. Better use tabs \t to adjust columns in all trailing printfs.
That can easily screw up the spacing. Better to use printf() correctly, such as
printf("%-10.10s%15d%15d%15d\n", n1, g1, w1, p1);
The above will insure consistent spacing
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343