Solution to Write a Program: Print a table of stars and zeroes. Your goal is to print … - Sikademy
Author Image

Archangel Macsika

Write a Program: Print a table of stars and zeroes. Your goal is to print a square table of alternating stars and zeroes. Ask the user to enter a size of the table. This 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. Do not create separate output strings for all combinations of error conditions – your program should build the output. Once a valid size is entered print the table to the console. Each row of the table should have alternating ‘*’ 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.

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question


#include <iostream> #include <cstdlib> using namespace std; int main() {     int n;     cin >> n;     if (n%2 == 0) {         cout << "n is not odd" << endl;         exit(1);     }     char ch;     for (int i=0; i<n; i++) {         if (i%2 == 0) {             ch = '*';         }         else {             ch = '0';         }         for (int j=0; j<n; j++) {             cout <<  ch << ' ';             ch = ch == '*' ? '0' : '*';         }         cout << endl;     }     return 0; }

Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1024-qpid-20