OutPuting an array with random Numbers

i can't seem to output the array wit the random numbers to a file like notepad for example, and i can't figure out why.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;

int RowTest();
int ColumnTest();
string GetFileName();
void ArrayFiller();
 
int main()
{
    int Row = RowTest();
    int Column = ColumnTest();
    int Array [50][50] ;
    string FileName = GetFileName();
    srand ((time(NULL)));
     
    return(0);

}
int RowTest()
    {
        int Row;
        cout << " Please enter a value for the row of the array that is between 2 and 50. \n";
        cin >> Row;
        while ( Row <= 2 || Row >= 50 )
        {
            cout << " Invalid input, please try again \n";
        }

        return Row;
}

int ColumnTest()
    {
        int Column;
        cout << " Please enter a value for the column of the array that is between 2 and 50 as well.\n";
        cin >> Column;
 
       while (1 >= Column || Column >= 51)
        {
            cout << " Invalid input, please try again \n";
        }
        return Column;
}

string GetFileName()
    {
        string FileName;

        cout << " Please enter the name of the file \n";
        cin >> FileName;

        return(FileName);
}
 
void ArrayFiller( int Array[50][50] , int Row , int Column )
{
    string FileName;
    ofstream FileOut;
    FileName = GetFileName();
    FileOut.open(FileName);
 
   for (int i = 0; i < Row; i++)
        for (int k = 0; k < Column; k++)
        {
           FileOut << Array[i][k] = rand() % 100 << ;
           FileOut.close();
         }

}
Last edited on
What would make the condition on line 29 change to false, if it is true initially? What in the body of the loop changes the condition?

Same for line 43.
omg im glad you brought that up cause i have no idea how to get the logic right so if they input the wrong thing, it will ask them to try it again.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<iostream>
#include<fstream>
#include<cstdlib>
#include<ctime>
#include<string>
using namespace std;

int RowTest();
int ColumnTest();
void ArrayFiller();
string GetFileName();
void PrintArray();

int main()
{
    int Row = RowTest();
    int Column = ColumnTest();
    int Array [50][50] ;
	string FileName = GetFileName();
	srand ((time(NULL)));
			
	
	return(0);
	
}

int RowTest()
{
    int Row;
   
	do
	{
		cout << "Enter the number of rows you would like in the array, that is between 2 and 50 \n";
		cin >> Row;
	}
	while ( (Row < 2) || (Row > 50) );
	
   
	return (Row);
}

int ColumnTest()
{
    int Column;
    do
	{
		cout << " Please enter a value for the column of the array that is between 2 and 50.\n";
		cin >> Column;
	}
	while ( (Column < 2) || (Column > 50) );

    return Column;
}

string GetFileName()
{
	string FileName;
	
	cout << " Please enter the name of the file \n";
	cin >> FileName;
	
	return(FileName);
}

 void ArrayFiller( int Array[50][50] , int Row , int Column )

{
	for ( int i = 0; i < Row; i++ )
		for ( int k = 0; k < Column; k++ )
		{ 
			Array[i][k] = rand() % 100 ;
		}
	
}

void PrintArray( ostream& out, int Array[50][50], int Row, int Column )
{

Last edited on
Unnecessary repetition. Think about this:
1
2
3
4
5
6
7
8
9
10
11
12
int input( string text )
{
  int value = 2; // safe default, in case the input fails
  do {
    cout << text << " the array, that is between 2 and 50, inclusive\n";
  } while ( cin >> value && ((value < 2) || (50 < value)) );
  return value;
}


auto row = input( "Enter the number of rows you would like in" );
auto col = input( "Please enter a value for the column of" );
Topic archived. No new replies allowed.