Answer to Question #249520 in C++ for Bryce

Question #249520

Write a Program: Print a table of stars and zeroes

print a square table of alternating stars and zeroes.


Ask the user to enter a size of the table. The number should be odd. Since the table is square the number of rows and columns will be the same and should be equal to the entered size. The valid range for the size is from 3 to 15, inclusive.


Use a loop to make sure the entered size is odd and within the range. Output a descriptive error message if an invalid size is entered. The error message should indicate if the size is even, or less than the minimum, or larger than the maximum.


If more than one error condition appears. Don't create separate output strings for all combinations of error conditions


Each row in said table should have ‘*’ and ‘0’ symbols separated by a space. Each column of the table should also have alternating ‘*’ and ‘0’ symbols. All corners should have the ‘*’ symbol.





1
Expert's answer
2021-10-11T00:05:17-0400
#include<iostream>
using namespace std;


int main()
{
	int i, j, N;
	
	cout << "\nPlease Enter Any Side of Square  =  ";
	cin >> N;
	if(N%2 !=0 &&N>3 &&N<15){
	
	for (i = 0; i <N; i++)
	{
		for (j = 0; j < N; j++)
		{
			if(j%2==0){
			cout << " * ";}
			else {
				cout<<" 0 ";
			}
		}
		cout << "\n";
	}}
	else if(N%2==0 && N>3 && N<15){
		cout<<"Even number, the number should be odd";
	}
	else if(N<3){
		cout<<"Number is less than minimum";
	}
	else if(N>15){
		cout<<"Number is grater than maximum";
	}
	else{
		cout<<"Invalid number";
	}
 	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS