Thread: text file

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    14

    text file

    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;
    }
    Last edited by bj31t; 04-28-2004 at 12:52 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  3. Simple File encryption
    By caroundw5h in forum C Programming
    Replies: 2
    Last Post: 10-13-2004, 10:51 PM
  4. checking values in a text file
    By darfader in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 02:13 AM
  5. what does this mean to you?
    By pkananen in forum C++ Programming
    Replies: 8
    Last Post: 02-04-2002, 03:58 PM