-
Random Numbers
Hey, guys. I'm fairly new to the C programming language. I'm trying to generate a random number and display a line of text based on that number. This is what I have so far.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
srand(time(NULL));
int number = rand() % 3;
if (number = 1)
printf("This is the first line of text.\n");
if (number = 2)
printf("This is the second line of text.\n");
}
I want this to print either "This is the first line of text." or "This is the second line of text.". When I compile and run it, it prints both. Can someone help me with this? Thanks.
-
-
Quote:
Originally Posted by
Sipher
use == instead of =
Thank you! Thank you SO MUCH!!!
-
Don't mention it. I always want to help others if i can