can you helpp me plz22

2. Write a C++ program that reads in the side of a square and prints the square out of asterisks. Your program should work for square of all sizes between 1 and 20, when the user enter other sizes the program should display an error message.

Sample Run 1:

Enter the square side: 5
*****
*****
*****
*****
*****

Sample Run 2:
Enter the square side:21
invalid input. the side of a square should be between 1 and 20.
What is the problem you're having with your code?
This will work, but if this is an assignment and you don't understand what it does, you better do some research before you turn it in.

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
#include <iostream>
#include <sstream>

using namespace std;

int main()
{

	int size;

	cout << "What is the size of your square (1-20)? ";
	cin >> size;
	while (size < 1 || size > 20)
	{
		if (cin.fail()) return 1;
		cout << "\nInvalid square size!\n";
		cout << "What is the size of your square (1-20)? ";
		cin >> size;
	}

	stringstream rowLine;
	for (int i=0; i<size; ++i) rowLine << "*";

	for (int i=0; i<size; ++i) cout << rowLine.str() << "\n";

	system("pause");
	return 0;
}
Last edited on
HellfireXP (35) mrs thanke you so so mauch i am very happy and i seen im dovelpoment my self becouse we hell me thankes agin
Topic archived. No new replies allowed.