Re: C
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>) |