- Joined
- Oct 25, 2009
- Messages
- 59
- Reaction score
- 0
- Points
- 6
OK, I have been trying for about an hour now to get this to work. 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.
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?
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?