I have recently made a till training program where it tells you what the total sale, asks you to type in the cash given by the customer and then tells you the change that needs to be given.
However, to come up with the random total sales each time I used the code below:
1 2 3
|
srand(time(NULL));
totalSale = rand() % 2000 + 1; //Sale up to £20.00
totalSale /= 100.00;
|
So I used rand() to generate a new random number while using srand() to generate a new seed using time. I did include the header <time.h> and the program runs fine but the random numbers are not random, they just keep starting at a random number and each new random number keeps increasing. This program did work in Windows 7, when I upgraded to Windows 10 this happened.
Have I done something wrong or does making a new seed work differently in Windows 10? I am using VS 2015 as well.
For example here is a program run:
The Total Sale is: 17.33
Enter the ammount given: 2000
Amount given: 20
Change: 2.67
The Total Sale is: 17.39
Enter the ammount given: 2000
Amount given: 20
Change: 2.61
The Total Sale is: 17.49
Enter the ammount given: 2000
Amount given: 20
Change: 2.51
The Total Sale is: 17.56
Enter the ammount given: 2000
Amount given: 20
Change: 2.44
The Total Sale is: 17.59
Enter the ammount given: 2000
Amount given: 20
Change: 2.41
The Total Sale is: 17.72
Enter the ammount given:
As you can see when I put in £20 the next total sale just increases and is not random.
I really cannot see what is wrong here.