0

This is my assignment for compsci and im stuck at the very end of how to get the field of stars '*' to repeat how ever many times the user wants.

Write a program that prints out a series of fields of stars (i.e., “*”). Each field will have n rows and m columns. Enable the user to enter the number of rows (at least 1 but no more than 5) and columns (at least 5 but no more than 50), as well as the number of fields (at least 3, but no more than 10). Each field must be separated by 3 complete blank lines.

Your program must include at least two functions: one to get the input data from the user, and one to draw each field. Use for loops to construct the fields, as well as to print out the multiple fields. Do NOT use a string of “”. Rather, print out individual “”.

code

#include <iostream>

using namespace std;

void displayField(int numrows, int numcolums);

void getData (int numrows, int numcolumns, int numfields);

const char c = '*';



int main(void)
{
    int numrows, numcolumns, numfields;

    cout << "Welcome to the banner creation program!" << endl;

    cout << "Enter the number of rows (1 - 5) --> ";
    cin >> numrows;

    if(numrows<1 || numrows>5){
        cout << "Your entered value is outside the range!" << endl;
        cout << "Program will now halt..." << endl;
        exit(0);}


    cout << "Enter the number of columns (5 - 50) --> ";
    cin >> numcolumns;

    if(numcolumns<5 || numcolumns>50){
        cout << "Your entered value is outside the range!" << endl;
        cout << "Program will now halt..." << endl;
        exit(0);
    }

    cout << "Enter the number of rows (3 - 10) --> ";
    cin >> numfields;

    if(numfields<3 || numrows>10){
        cout << "Your entered value is outside the range!" << endl;
        cout << "Program will now halt..." << endl;
        exit(0);
    }
for(int i=1; i<=numrows; i++){
    for (int j=1; j<=numcolumns; j++)
            cout << c;
        cout <<endl;

}


}

1 Answers1

0

To break things down...

1) For each field, there are numerous rows.

2) For each row there are numerous columns

3) For each column there is a character, '*'

Written like that now, we know that we need to have 3 different loops all nested. But there are constraints.

At the end of each row we need to start a new line.

At the end of each field we need three blank lines.

for (int i = 0; i < numFields; i++) {
  for (int j = 0; j < numRows; j++) {
    for (int k = 0; k < numColumns; k++) {
      cout << c;
    }
    cout << endl;
  }
  cout << endl << endl << endl;
}

Additionally, you should double check your work. I've noticed you're using a few variables in the wrong places hint hint.

Grambot
  • 4,370
  • 5
  • 28
  • 43
  • Just to make sure you don't forget something. Check your if statements again. Specifically what variables are being checked at what time. – Grambot Nov 09 '12 at 16:42