# I'm a noob and I need help.

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 10-13-2008
nifear4
I'm a noob and I need help.
Hi everyone. Before you read this thread, just warning you, you guys might get frustrated because I'm just that bad at programming, so pardon me if I don't really understand whats going on.

What I'm trying just to trying to do some basic stuff, like looping numbers and stuff, so far I got down to rand int's and what I'm trying to do is loop random numbers from 0-1000 (including 0 and 1000). And for every even number, i want it to say even and for every odd number I want it to say odd, and the only way the loop will stop is if the number is divisible by 10 evenly, so like 10, 20, 30, etc.

so far this is what I got,
---------------------------------------------------------
Code:

```#include<stdio.h> #include<stdlib.h> int main() { int x, p; srand(time(NULL)); x = rand() &#37; 1001;  // please tell me if this is the right function i should be using for my rand in order for it to be limited from 0 to 1000 while (p != (x / 10) == 0) { if(x / 2 == 0) {printf("The number %d is even.\n", p); } else printf("The number %d is odd.\n", p); }```
----------------------------------------------
And then i have no idea what to do from here.... I don't even know if this is correct, I wrote a flowchart saying that I want and how i want to do it, but its pretty simple for you guys i bet. Sorry that I'm a noob, its just that I really wwant to get into programming because I wanted to program ever since I was 12. Thanks.

-Yi
• 10-13-2008
master5001
Indent...

Code:

```#include<stdio.h> #include<stdlib.h> int main() {   int x, p;   srand(time(NULL));   x = rand() &#37; 1001;    // please tell me if this is the right function i should be using for my rand in order for it to be  limited from 0 to 1000   while (p != (x / 10) == 0) /* Wow... Letting the compiler decide how to handle this one? Brave guy */     if(x / 2)       printf("The number %d is even.\n", p);     else       printf("The number %d is odd.\n", p); }```
p != (x / 10) == 0

That is a problem. It won't do what you want it to do since you are combining two conditions.

It should process (x/10) == 0, first. Then check to see if that is equal to 10. Thus it will only handle something that is a power of 10. Which oddly sounds like the problem you are having.
• 10-13-2008
nifear4
Thanks for helping, I'll give it a try. I'll report as soon as possible and let you guys know the results.

Again, thanks for responding really fast.

-Yi
• 10-13-2008
master5001
Never before have I been commended for not doing my homework. Thanks, nifear4.
• 10-13-2008
C_ntua
• 10-13-2008
master5001
Quote:

Originally Posted by C_ntua

Amusing. I will have to bookmark this one for later.
• 10-13-2008
nifear4
Just in response to the link, i am a newb, not a noob. lol

OTL. thats very interesting, gotta show that to my friends. Thanks.

-Yi
• 10-14-2008
nifear4
Code:

```#include <stdio.h> #include <stdlib.h> #include <time.h> //The function names int main(void) { int x, y; srand(time(NULL)); x = rand() &#37; 100; //Code #1 if(x % 10 != 0) { if (x % 2 == 0){ printf("YOU GOT THE NUMBER %d AND ITS A EVEN NUMBER!\n", x); fflush(stdout); } else printf("YOU GOT THE NUMBER %d AND ITS A ODD NUMBER!\n", x); fflush(stdout); } if (x % 10 == 0) { if(x == 0) printf("You got the number %d, so we can't start!", x); else printf("YOU GOT THE NUMBER %d AND ITS AN EVEN NUMBER, BUT YOU ARE THE WEAKEST LINK, GOOD-BYE!\n", x); return (EXIT_SUCCESS); } y = x; x = rand() % 100; //Code #2 while(x % 10 != 0) { if (x % 2 == 0 && x > y) { printf("The NUMBER is %d (even) which is > %d also the previous integer.\n", x, y); fflush(stdout); } if (x % 2 != 0 && x > y) { printf("The NUMBER is %d (odd) which is > %d also the previous integer.\n", x, y); fflush(stdout); } if (x % 2 == 0 && x < y) { printf("The NUMBER is %d (even) which is < %d also the previous integer.\n", x, y); fflush(stdout); } if (x % 2 != 0 && x < y) { printf("The NUMBER is %d (odd) which is < %d also the previous integer.\n", x, y); fflush(stdout); } y = x; x = rand() % 100; } if (x == 0) printf("YOU GOT THE NUMBER %d, so we can't start :'(\n", x); else printf("YOU GOT THE NUMBER %d AND ITS AN EVEN NUMBER, BUT YOU ARE THE WEAKEST LINK, GOOD-BYE!\n", x); return (EXIT_SUCCESS); }```

This is the code I made last night with the code, thank you guys for helping me solve this problem.
• 10-14-2008
master5001
Much cleaner. Well except for the lack of indentation. But your actual code is more on the ball.
• 10-14-2008
Elysia
You cannot possible expect us to read that unreadable code mess.
• 10-14-2008
Salem
So where's the indentation?
• 10-14-2008
master5001
Salem is up to over 19,300 posts. Do you realize roughtly 19,000 of those posts were demands to fix indentation or use code tags?
• 10-14-2008
Elysia
Hey, quick and easy posts ;)
It's the easiest way to spam, while not spamming :p
But seriously, it's unfortunately a needed reminder.
• 10-14-2008
master5001
I notice the board will sometimes demand I put code tags around things in my posts that aren't even really code. How come it won't demand indentation if it detects code tags but no use of either the tab character or multiple consecutive spaces? Just a thought Kermi.
• 10-14-2008
Elysia
It does demand code tags when it detects both { and } in the reply and not within code tags.
I'm not sure how people are getting around this, unless they're just posting a reply and directly editing it afterwards.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last