lundi 2 mars 2015

How to randomly assign values in C?

Any ideas on how to randomly assign values in C? Any help would be great


Your 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 what i have so far for my code



#include<stdio.h>
#include<time.h>
#include<stdlib.h>

int main (void)
{
int numsales;
srand(time(NULL));

printf("Enter the number of sales to simulate: ");
scanf("%d", &numsales);
while(numsales<1 || numsales>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",&numsales);
}
return 0;
}




Aucun commentaire:

Enregistrer un commentaire