The above video goes away if you are a member and logged in, so log in now!

 Would you like to get all the newest Gaming News fromQJ.NET in your email each day? Want to learn more about the team who brings you the QJ news?

## Problems in C

This is a discussion on Problems in C within the PSP Development Forum forums, part of the PSP Development, Hacks, and Homebrew category; Ok, I think I've posted this in the wrong place, but I couldn't find anywhere better, and I saw the ...

 Tweet
1. ## Problems in C

Ok, I think I've posted this in the wrong place, but I couldn't find anywhere better, and I saw the C/C++ tutorial here too... if anyone feels this should be moved, ask a mod, just don't flame me...

Anyway, I just want to know a couple of things, I have searched on Google, but not found anything helpful, and I would search here, but my dialup connection hates this forum...

How do I use the logic function OR? What header files do I need? Also, can someone give me some sort of idea as how to add it to my code.
I know that
Code:
`while((sgx==230) && (sgy==20))`
works, so I tried switching to
Code:
`while((sgx==230) OR (sgy==20))`
but I got an error, I've delved into header files and so on, but can't find what I'm meant to do.

The other question, how do I pass a totally random number? I've thought about using time, but I can't limit this to a range... I have on the other hand thought about dividing it and finding the remainder to limit... so I guess my question is, how do I limit srand, or how do I return a remainder of an equation? (The latter is probably more helpful as it has other applications).

-Aura

2. Well in response to the first question, logical OR is || (logical AND is &&)

As for the random number thing, I don't know myself.

3. Logical Operators

There is a link to bitwise operators as well, so that should help.

4. int % int = remainder (modulo)

5. Wow, that was quick, wasn't expecting any replies for a while

I'm gonna put those things into my game now, the only thing I'm slightly confused about is the returning remainder, but I've not tried yet and I could just be over complicating things.

Again, thanks for all the help :Punk:

-Aura

6. 10 % 5 == 0
5 goes into 10 twice, without any remainder.

11 % 5 == 1
And so on.

7. For future reference, this should be in the C/C++ Help Thread stickied in this forum.

8. I think we should lock the current C/C++ threads and rename them to[Archives] C/C++ Help, then make a new one.

9. One last question....

Ugh... what have I done wrong here...?
Code:
```           battle % 2 == monster;
monster+=1;
printf("%d", monster);```
Battle is a random variable, its divded by 2, so that its remainder can only equal 0 or 1, then I add 1 to it, bringing it up to 1 or 2... but when I print it on screen to check, I'm getting something way out, I've given "monster" a number before this code, and I always get that number + 1, and not 1 or 2 as I would hope.

Thanks again.

-Aura

10. battle % 2 == monster;

That line doesn't do anything. It checks if battle % 2 (which can be done also by battle & 1; it has the same effect, and the latter is probably fast) if equal to monster...and then discards the value.

11. Originally Posted by Auraomega
One last question....

Ugh... what have I done wrong here...?
Code:
```           battle % 2 == monster;
monster+=1;
printf("%d", monster);```
Battle is a random variable, its divded by 2, so that its remainder can only equal 0 or 1, then I add 1 to it, bringing it up to 1 or 2... but when I print it on screen to check, I'm getting something way out, I've given "monster" a number before this code, and I always get that number + 1, and not 1 or 2 as I would hope.

Thanks again.

-Aura

the code structure is wrong. first or all, you use two '=' which compares two things, not assign. 2nd, you assign on the opposite side of the equal sign. try this:

Code:
```           monster = (battle % 2) +1;
printf("%d", monster);```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

All times are GMT -8. The time now is 02:13 AM.

Use of this Web site constitutes acceptance of the TERMS & CONDITIONS and PRIVACY POLICY