I am stuck on a code and I am in need of assistance.

Write a program that asks the user for a positive integer no greater than 15.
The program should then store a square on a file using the character ‘X’. The number
entered by the user will be the length of each side of the square. For example, if the
user enters 5, the program store the following pattern in a file named “pattern.dat”:
XXXXX
XXXXX
XXXXX
XXXXX
XXXXX
The program should then read the stored pattern from the file you just created and display the
pattern on the screen.

#include <iostream>
using namespace std;

int main ()
{
int number;
cout<<"Enter A Even Number Less Than 15 to make a square out of: ";
cin >> number;
if(number > 15)
cout <<"Your input must be less than 15!";
else
for (int j=0; j < number; j++)
for(int i=0; i < number; i++)
{
cout << "X";
}
cout<<endl;
return 0;
}

That is all I have, I am just trying to get the pattern to display correctly.
okay i fixed the code but now i need help writing it to a file.

#include <iostream>
using namespace std;
int main ()
{
int number;
cout<<"Enter a positive integer no greater than 15: "<<" "<<endl;
cin>>number;
if (number < 1)
cout<<"The Number Must Be Positive!!";
else if (number > 15)
cout<<"The Number Must Be Less Than 15!!";
else
{
for (int i=0; i <number; i++)
{
for (int j=0; j <number; j++)
{
cout<<'X';
}
cout<<endl;
}
}
return 0;
}
I am new to programming myself and I must say, you should look at the tutorials on this website. Here is one that should answer your question if I understand it correctly. http://www.cplusplus.com/doc/tutorial/files/
Topic archived. No new replies allowed.