Write a program that asks the user for a positive integer no greater than 15. Th
ID: 3696204 • Letter: W
Question
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. Please don't use any thing too complicated that I might not have covered in my class add Comments to Help me understand the program better, I have been having problems with it and I want to make sure I fully understand it. Thank You!
Explanation / Answer
Program: You are not mentioned the particular language to write the code. so i am using c++ language to writing this code. The code as follows:
#include <iostream>
using namespace std;
int main ()
{
int number;
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;
}
system("pause");
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.