Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   C Programming Homework Help Needed (http://www.chiefdelphi.com/forums/showthread.php?t=57552)

David Doerr 14-09-2008 21:48

Re: C Programming Homework Help Needed
 
Hi Pat,

Shouldn't your "for" loop start with its index set to 2 rather than 3? Your array size is 3 -- with an index of 0, 1 or 2.

Dave D

Pat McCarthy 14-09-2008 21:53

Re: C Programming Homework Help Needed
 
I just fixed that, but I'm still having the same problem.
As an example, I'll enter 1111 and the error checking appears to work, but then I'll enter 1211 and it will say there is an error with the second digit. This happens for any digit that has a value of 2.

David Doerr 14-09-2008 21:56

Re: C Programming Homework Help Needed
 
Sorry, no, your index is OK, but your array declaration should read

int num[4];

not

int num[3];

Pat McCarthy 14-09-2008 21:59

Re: C Programming Homework Help Needed
 
Thanks Dave! That seems to have taken care of it!
It's been a year since I've written code, so I'm a bit rusty. :p

David Doerr 14-09-2008 22:04

Re: C Programming Homework Help Needed
 
That C structured programming class seems to be dragging out for quite some time. It might be about time to start in on C++.

:)

Pat McCarthy 14-09-2008 22:09

Re: C Programming Homework Help Needed
 
Quote:

Originally Posted by David Doerr (Post 765504)
That C structured programming class seems to be dragging out for quite some time. It might be about time to start in on C++.

:)

Nah, it's been over multiple classes, just all using some C as a component of them.

StormRoBoT 17-09-2008 13:18

C Programming Homework Help Needed
 
help on palindrome

i have make a program that can trace palindrome number but i need it to loop over and over again till i keyin -1 then only the program terminate


this is the code that i have used:

Code:

#include<stdio.h>
#include<string.h>

void main()
{
char strsrc[5];
char strtmp[5];

printf("\n Enter a five-digit number ( -1 to end ): "); gets(strsrc);

strcpy(strtmp,strsrc);
strrev(strtmp);

if(strcmp(strsrc,strtmp)==0)
printf("\n %s is a palindrome\n",strsrc);
else
printf("\n %s is not a palindrome\n",strsrc);
}

any one can help?

Alan Anderson 17-09-2008 15:56

Re: C Programming Homework Help Needed
 
Quote:

Originally Posted by StormRoBoT (Post 765949)
i have make a program that can trace palindrome number but i need it to loop over and over again till i keyin -1 then only the program terminate

any one can help?

You want it to loop? Hint: use a while statement that never ends, putting all the things inside it that you want to keep executing over and over.

You want it to end? Hint: use an exit statement, but only execute it when the program is supposed to terminate.

ShotgunNinja 27-09-2008 22:15

Re: C Programming Homework Help Needed
 
What exactly do you mean by "loop"? Do you want it to repeatedly ask for a number, then check it for palindrome-ness (sorry, vocabulary suffered a non-Build season hit :D ) , or do you want to loop through calculations (a bit daft, but I don't know what the professor/employer expects...), or what?


All times are GMT -5. The time now is 13:22.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi