• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

C Programming Help

saahmed

Golden Member
I am having an error in my code below and cant figure out why. It must be some stupid smalle error. After doing a lot of testing, I have conluded that the first time through goes fine. But when it loops through a subsequent times it automatically returns 0, though the if statement is not true. Any idea what is wrong here?

setCardinality returns the size of the array.

 
Maybe I should be a bit more clear.

setCardinality just returns the size of the array. So, the for looping through each element of the array and stopping at the end of it.

isMember just searches for the paricular number in the particular array. So in this case it is searching for the number at element i of a (a[I]) in array b. The function returns 0 if the number is found in the array and 1 if it is not.

This function is supposed to determine if the two arrays are subsets, meaning that all of the elements in array can be found in array b. The problem is that after the first loop, the function only returns 0, regardless if the if statement is true or false.
 
Does anyone see anything wrong?
I know isMember is working properly because I can search for a number and it always returns the correct answer. I will post it anyway, maybe there is something that needs to be changed.

It returns 0 when the number is not found.
 
Originally posted by: DaveSimmons
if((isMember(b[ i ],b))==0){

why are you searching to see if b [ i ] is in b ? Seems a little pointless 🙂


Oh, no I realized that and I changed it to (isMember(a[ i ],b))==0).
I didnt know I pasted the older thing. But, yeh, it has the same problem with a,b.

It is weird becuase I put some printf statements in the function and it seems like it is returning 0 without even going into the if statement. And it goes through the for loop too many times.
 
If anybody is willing to, I am attaching the file. If somebody could just paste it into visual studio and see what the problem might be? I think it is something stupid and minor.
 
Finsihed the whole assignment finally. Took forever. Probably spent like almost 15 hours, but when I look back at it, it seems quite simple.
 
You call 15 hours 'forever'? Noob! 😛

I spent 14 hours in a row last saturday on a graphics programming assignment (due at midnight). Felt weird to be able to do the whole thing in one day but it reminded me why it's a good idea to start ahead of time and put waaayyy more time into it. 🙂
 
as i was learning to program i found that thinking through how something is going to work prior to writing any code or even sitting in front of a computer helped enormously. it cut down those 14-16 hour programming sessions significantly.
 
Originally posted by: kamper
You call 15 hours 'forever'? Noob! 😛

I spent 14 hours in a row last saturday on a graphics programming assignment (due at midnight). Felt weird to be able to do the whole thing in one day but it reminded me why it's a good idea to start ahead of time and put waaayyy more time into it. 🙂

It was actually probably longer than that, more like 20 something figuring in all the reading and just sitting there staring at my computer not knowing what to do next. But yeh, for me that is a long time, I can usually whiz through my homework for other classes.
 
Originally posted by: saahmed
Finsihed the whole assignment finally. Took forever. Probably spent like almost 15 hours, but when I look back at it, it seems quite simple.

Welcome to the world of computer programming.

Dave
 
Back
Top