X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: "Robert B. Clark" Newsgroups: comp.os.msdos.djgpp Subject: Re: another newbie C question Date: Tue, 25 Nov 2003 13:39:32 -0500 Organization: ClarkWehyr Enterprises Lines: 98 Message-ID: References: NNTP-Posting-Host: dial-1-201-12-02.ind.iquest.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.iquest.net 1069785685 70627 209.43.97.1 (25 Nov 2003 18:41:25 GMT) X-Complaints-To: usenet AT news DOT iquest DOT net NNTP-Posting-Date: Tue, 25 Nov 2003 18:41:25 +0000 (UTC) X-Newsreader: Forte Agent 1.9/32.560 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Tue, 25 Nov 2003 16:51:30 -0000, "Keith__" wrote: >im having probs with the following program. i need it to loop after a >percentage is entered, asking for another one continuosly unless the >percentage is a negative in which case the program should end. could someone >please show me what im missing. For starters, you're missing a loop. :-) >#include > >int percentage; >int Result; >int Fail; >int Referal; >int Pass; >int Merit; >int Distinction; Except for percentage, these variables do not appear to be used at all. > >void main() int main(void) main returns an int, not void. > >{ > printf("Welcome to the Result Identifier. Enter a negative to Exit\n"); > printf("Enter your percentage: "); Without a newline or explicitly flushing the output, your prompt may not be shown. Either add a newline to the end of your prompt, or preferably fflush(stdout); > scanf("%d", &percentage); > > if(percentage < 35) > > { > printf("Your final mark is: Fail\n"); > > } If percentage is < 0, your "fail" message will also be displayed. This may or may not be by design. > if(percentage > 35 && percentage < 50) > > { > printf("Your final mark is: Referal\n"); > } > > if(percentage > 50 && percentage < 65) > > { > printf("Your final mark is: Pass\n"); > } What if your percentage is 35, 50, 65 or 80? What answer would your program give? > if(percentage < 0) > > { > > } Empty block here. > >} > There is no loop in your code. A do-while loop would be ideal for this type of application. Try this: int main(void) { do { /* get pct & process it */ } while (pct >= 0); return 0; } -- Robert B. Clark (email ROT13'ed) Visit ClarkWehyr Enterprises On-Line at http://www.3clarks.com/ClarkWehyr/