# Thread: random number between two values

1. ## random number between two values

Hi I wrote a program for a programming class in which we had to make a test in which to see what an earthquake is on a richter scale. Here it is:
#include "stdafx.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
int n = 0;

if(n <= 5.0)
{
printf("There is little or no damage dealt by the earthquake!");
}
else
{
if(n >= 5.0 && n < 5.5)
{
printf("Some damage was dealt by the earthquake!");
}
else
{
if(n >= 5.5 && n < 6.5)
{
printf("Serious damage was dealt as a result of the earthquake!");
}
else
{
if(n >= 6.5 && n < 7.5)
{
printf("Major disator from the earthquake!");
}
else
{
if(n>7.5)
{
printf("There is a state of emergency because the earthquake has totaled most buildings!!");
}
}
}
}
}

return 0;
}

My question is how do I make a random number between 1 and 8 including both 1 and 8 and assigning it to n so it really shows how the program works and if I do stuff like this it's worth xtra credit. I sorta need it b\c the teacher sucks and doesn't really state clearly when we have assignments. Thanks ^_^

2. >My question is how do I make a random number between 1 and 8 including both 1 and 8 and assigning it to n

-Prelude

3. hmm.. i didn't think of doing that while i was searching the post for answers. I know how to be on a message board, those other threads didn't answer my question, they beat around the bush without providing real answers without digging them out, so I asked my question

4. n = (rand() % 8) + 1;

quick example.

5. Next time you post your code, use code-tags

6. > I know how to be on a message board, those other threads didn't answer my question, they beat around the bush without providing real answers without digging them out
You didn't look very hard then. I've answered this question countless times very directly, every answer to it I've seen that wasn't mine did so as well.

-Prelude