delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/11/25/13:45:52

X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f
From: "Robert B. Clark" <epynex AT 3pynexf DOT pbz>
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: <dg67sv8dtg8otqncs7qao0r80ujhcbg4ac@4ax.com>
References: <bq01aj$btt$1 AT news6 DOT svr DOT pol DOT co DOT uk>
NNTP-Posting-Host: dial-1-201-12-02.ind.iquest.net
Mime-Version: 1.0
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__" <asdth AT hotmail DOT com> 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 <stdio.h>
>
>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");
> }

<snip>

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019