This is a discussion on problem with if...can you help? within the C Programming forums, part of the General Programming Boards category; xxxx...
Last edited by blinded; 04-09-2010 at 05:18 PM. Reason: delete
Step 1: Put your code inside code tags. You can either highlight your code and click the # sign in the edit window, or you can type [code] at the beginning of the code and [/code] at the end.
Step 2. Why do you think "it" (whatever or whoever "it" is) has a problem (whatever the problem is, which is unspecified) with the if comparison (whichever of the if comparisons you have in your code)?
<< !! Posting Code? Read this First !! >>
That does not mean "Posting Code? Ignore this!"
#3 Describe the problem.
> int n;
> int s[n];
What garbage value of n is being used to specify the sizes of these arrays?
There's a 50% chance it's NEGATIVE!
> for (int i=1; i<=n; i++)
Arrays begin at 0, not 1
Oh, and having variables called p and P (differing only by case) will confuse you. Try picking some meaningful names.
For C programming, try using these options (for gcc)
It would throw out a lot of the dubious code you have.Code:gcc -W -Wall -ansi -pedantic -O2 prog.c
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.