| | |
0 as percent
Thread Solved |
We i compile this program is shows that percents as 0.... any suggestions.
C Syntax (Toggle Plain Text)
#include <stdio.h> #include "simpio.h" #include "strlib.h" #include "random.h" #include <math.h> int main() { int g1, g2, g3, g4, w1, w2, w3, w4, p1, p2, p3, p4; string n1; string n2; string n3; string n4; //-------------------------------------------// printf("Enter first name: "); n1 = GetLine(); printf("Enter games played for %s: ", n1); g1 = GetInteger(); printf("Enter games won for %s: ", n1); w1 = GetInteger(); //-------------------------------------------// printf("\n"); //-------------------------------------------// printf("Enter second name: "); n2 = GetLine(); printf("Enter games played for %s: ", n2); g2 = GetInteger(); printf("Enter games won for %s: ", n2); w2 = GetInteger(); //-------------------------------------------// printf("\n"); //-------------------------------------------// printf("Enter thrid name: "); n3 = GetLine(); printf("Enter games played for %s: ", n3); g3 = GetInteger(); printf("Enter games won for %s: ", n3); w3 = GetInteger(); //-------------------------------------------// printf("\n"); //-------------------------------------------// printf("Enter fourth name: "); n4 = GetLine(); printf("Enter games played for %s: ", n4); g4 = GetInteger(); printf("Enter games won for %s: ", n4); w4 = GetInteger(); //-------------------------------------------// printf("\n"); printf("\n"); //-------------------------------------------// //---------------Calculations----------------// p1 = w1/g2*100; p2 = w2/g2*100; p3 = w3/g3*100; p4 = w4/g4*100; //-------------------------------------------// printf("Name Games Played Games Won Winning %\n"); printf("---- ------------ --------- ---------\n"); printf("%s %d %d %d\n", n1, g1, w1, p1); printf("%s %d %d %d\n", n2, g2, w2, p2); printf("%s %d %d %d\n", n3, g3, w3, p3); printf("%s %d %d %d\n", n4, g4, w4, p4); system("pause"); }
_________________________
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
||||||||||[][][]|||||||||||||||||||
|||||||||||||||____|
||||||||||
||||||||||
1. Follow Salem's advice (better use
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.
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.
Last edited by Ancient Dragon; Jul 27th, 2008 at 12:28 pm. Reason: correct icode tags
>>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
The above will insure consistent spacing
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
Last edited by Ancient Dragon; Jul 27th, 2008 at 12:34 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Converting to a percent (Visual Basic 4 / 5 / 6)
- Help with calculating a percent amount (Python)
- books cheap on LI (IT Professionals' Lounge)
- "Generate" percent... (C++)
- Has Acacia threatened to sue you yet? (Geeks' Lounge)
- graphics card (Monitors, Displays and Video Cards)
- windows problems... (Windows NT / 2000 / XP)
Other Threads in the C Forum
- Previous Thread: remove errors
- Next Thread: Reading numbers into an array from a file
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o ide inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






