home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:16920 comp.lang.c++:16680 comp.misc:4359
- 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
- From: fhi0055@hq.dla.mil (Marc Poole)
- Newsgroups: comp.lang.c,comp.lang.c++,comp.misc
- Subject: Confused
- Message-ID: <957@hq.dla.mil>
- Date: 20 Nov 92 16:07:52 GMT
- Followup-To: comp.lang.c,comp.lang.c++,comp.misc
- Organization: HQ Defense Logistics Agency/DASC, Cameron Station, VA
- Lines: 54
-
-
- The following is a program that I am trying to write. I can not seem
- how to get the outer loop to work. The situation is, the inner loop
- will run until it is finished, when it falls through the program should
- prompt for another int input. If the user inputs 0 then the whole
- program will end. If the user inputs any other number, the loop will
- continue.
-
- My problem is I can't seem to contruct the outer loop to end once 0 is
- entered. I either get an endless loop (with wrong answers the 2nd time
- through) or I get no answer after input of first int and the program
- ends.
-
- #include <stdio.h>
- main()
- {
- float answr;
- int fact;
- int count;
- count = 1;
- printf ("This program is designed to print the factoral of a number ");
- printf ("entered by the user.\n");
- printf ("Enter you number: ____\b\b\b\b");
- scanf ("%d",&fact);
-
- while
- {
- while (fact > 0)
- {
- count = count * fact--;
- }
- answr = count;
- printf ("%e", answr);
- printf ("\n");
- printf ("Enter another number or 0 to quit: ___\b\b\b");
- }
-
-
- printf ("\n");
- }
-
- I left the while statement in the beginning of the outer loop, because
- that's the loop I am trying to use. It's the coding for that statement
- I can't figure. Should scanf come after the first while, with it or is
- while not correct at all?
-
- If anyone can help or steer me in right direction please let me know.
-
- Hints and not answers would be greatly appreciated, explanations would
- be appreciated aslo.
-
- mpoole@hq.dla.mil | To some avail
-
-
-