home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / c / 16920 < prev    next >
Encoding:
Text File  |  1992-11-20  |  2.0 KB  |  66 lines

  1. Xref: sparky comp.lang.c:16920 comp.lang.c++:16680 comp.misc:4359
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!udecc.engr.udayton.edu!blackbird.afit.af.mil!dsacg3.dsac.dla.mil!dsac.dla.mil!hq.dla.mil!fhi0055
  3. From: fhi0055@hq.dla.mil (Marc Poole)
  4. Newsgroups: comp.lang.c,comp.lang.c++,comp.misc
  5. Subject: Confused
  6. Message-ID: <957@hq.dla.mil>
  7. Date: 20 Nov 92 16:07:52 GMT
  8. Followup-To: comp.lang.c,comp.lang.c++,comp.misc
  9. Organization: HQ Defense Logistics Agency/DASC, Cameron Station, VA
  10. Lines: 54
  11.  
  12.  
  13.  The following is a program that I am trying to write.  I can not seem
  14.  how to get the outer loop to work.  The situation is, the inner loop
  15.  will run until it is finished, when it falls through the program should
  16.  prompt for another int input.  If the user inputs 0 then the whole
  17.  program will end.  If the user inputs any other number, the loop will
  18.  continue. 
  19.  
  20.  My problem is I can't seem to contruct the outer loop to end once 0 is
  21.  entered.  I either get an endless loop (with wrong answers the 2nd time
  22.  through) or I get no answer after input of first int and the program
  23.  ends.
  24.  
  25. #include <stdio.h>
  26. main()
  27. {
  28. float answr;
  29. int fact;
  30. int count;
  31. count = 1;
  32. printf ("This program is designed to print the factoral of a number ");
  33. printf ("entered by the user.\n");
  34. printf ("Enter you number: ____\b\b\b\b");
  35. scanf ("%d",&fact); 
  36.  
  37. while 
  38. {
  39.     while (fact > 0)
  40.        {
  41.        count = count * fact--;
  42.        }
  43. answr = count;
  44. printf ("%e", answr);
  45. printf ("\n");
  46. printf ("Enter another number or 0 to quit: ___\b\b\b");
  47. }
  48.  
  49.  
  50. printf ("\n");
  51. }
  52.  
  53.  I left the while statement in the beginning of the outer loop, because
  54.  that's the loop I am trying to use.  It's the coding for that statement
  55.  I can't figure.  Should scanf come after the first while, with it or is
  56.  while not correct at all?
  57.  
  58.  If anyone can help or steer me in right direction please let me know.
  59.  
  60.  Hints and not answers would be greatly appreciated, explanations would
  61.  be appreciated aslo.
  62.  
  63.  mpoole@hq.dla.mil                   |       To some avail
  64.  
  65.    
  66.