New to programming in C and I'm trying to generate a random number once. But when the program complies it generates 30 random numbers in the range that the users specifies. Would using an Array be easier? Any help would be good.
edit
the program should prompt the user to enter the number of sales to simulate in the range from 1 to 10000. Next, it should do the following for each simulated sale: choose a random employee to credit the sale for, randomly determine the total dollar amount of the sale, add that dollar amount to the chosen employee's running sales total, and increment the number of sales that employee has made.- This is basically what i'm trying to do. Sorry for the confusion
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
int main (void)
{
int n,c; // n is the number of sales to simulate, c is the counter
int id[30];// id[30] is the number of employees
srand(time(NULL));
int myVar;
printf("Enter the number of sales to simulate: ");
scanf("%d", &n);
while(n<1 || n>10000)//blocking while loop
{
//prompt user to enter proper number for calculation
printf("Error: Enter a proper number in the range from 1 to 10000: \a");
scanf("%d",&n);
}
printf("Id\n");//prints out the id
for (c = 0; c<30; c++)
{
id[c] = c;
printf("%d: ",id[c]); //prints out the id numbers starting from 0 and ending at 29
myVar = rand() % n + 1;//prints random number sale ranging from 1 to n for each employee but needs to print once for a random employee ranging from 1 to n. And should print zeros for the rest of the employees.
printf("\t%d\n", myVar);
}
return 0;
}