• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C


  • Subject: Re: C
  • From: Dave Rosborough <email@hidden>
  • Date: Fri, 29 Aug 2003 11:59:54 -0700

> int main()
> {
> int temp[31];
> int index, total;
> index = 0;
> do
> {
> printf("temp #%d, \
> to quit type 555: ", index);
> scanf("%d", &temp[index]);
> }
> while (index < 31 && temps[index-1] != 555);
> }

Looks to me like the main problem is you forget to increment the counter,
"index". Also a problem where you refer to "temps[index-1]" rather than
"temp[index-1]".

For stylistic reasons, I've never liked the do...while loop, especially when
I'm counting through something. Here's how I'd do it with a for loop
instead:

int main()
{
int temp[31];
int index, total;

for (index = 0; (index < 31) && (temp[index-1] != 555); index++) {
printf("temp #%d, \nto quit type 555: ", index);
scanf("%d", &temp[index]);
}
}


TTYL
DaveR
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >C (From: Michael Kozerew <email@hidden>)

  • Prev by Date: Re: C
  • Next by Date: Re: C
  • Previous by thread: Re: C
  • Next by thread: Re: C
  • Index(es):
    • Date
    • Thread