can anyone tell me why there is 18 numbers in the text file instead of 10. thanks
Code:
#include <fstream>
#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
void rand_seed()
{
int seed = static_cast<int>(time(0));
srand(seed);
}
int rand_int(int a, int b)
{
return a + rand() % (b - a + 1);
}
int main()
{
int response;
do
{
cout<<"Enter 1 for a list 2 to exit.";
cin>>response;
if (response == 1)
{
rand_seed();
ofstream fout;
fout.open("data.dat", ios::out);
int arr [10];
rand_seed();
int i;
for (i = 1; i <= 9; i++)
{
int d1 = rand_int(1, 99);
arr[i] = d1;
fout<<arr[i];
}
fout.close();
}
else
cout<<"Thank you!!!";
while (response == 1);
return 0;
}