Rows, Columns, Fields C++ program

Nov 12, 2009 at 12:59am
Hi everyone!

Here is the problem I was assigned:
Write a program that prints out a series of fields of stars(*). 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.

The 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.



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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//
//
// This program is for making a banner. It will allow the user to enter
// the number of rows, columns, and fields.

#include <iostream>

using namespace std;

void getVals(int numRows, int numColumns, int numFields);
void displayBanner(int numRows, int numColumns, int numFields);
void checkRows(int numRows);
void checkColumns(int numColumns);
void checkFields(int numFields);

const char c = '*';

int main(void)
{
int numRows=0, numColumns=0, numFields=0;
getVals(numRows, numColumns, numFields);
displayBanner(numRows, numColumns, numFields);

return 0;
}

void getVals(int numRows, int numColumns, int numFields)
{ 
cout << "Please enter the number of rows(1-5): ";
cin >> numRows;
checkRows(numRows);
cout << "Please enter the number of columns(5-50): ";
cin >> numColumns;
checkColumns(numColumns);
cout << "Please enter the number of fields(3-10): ";
cin >> numFields;
checkFields(numFields);
}

void displayBanner(int numRows, int numColumns, int numFields)
{
for(int i=1; i<=numRows; i++) {
for(int j=1; j<=numColumns; j++) {
for(int k=1; k<=numFields; k++) {
cout << c;
cout << endl;
}
}
cout << endl << endl;
}
}

void checkRows(int numRows)
{
while ((numRows < 1) || (numRows > 5)) {
cout << "Invalid value entered!\n";
cout << "Please re-enter your value, it must be from 1-5 inclusive: ";
cin >> numRows;
}
}

void checkColumns(int numColumns)
{
while ((numColumns < 5) || (numColumns > 50)) {
cout << "Invalid value entered!\n";
cout << "Please re-enter your value, it must be from 5-50 inclusive: ";
cin >> numColumns;
}
}

void checkFields(int numFields)
{
while ((numFields < 3) || (numFields > 10)) {
cout << "Invalid value entered!\n";
cout << "Please re-enter your value, it must be from 3-10 inclusive: ";
cin >> numFields;
}
}


Nov 12, 2009 at 1:00am
The problems that I am having:

1. Nothing happens when I run the program.
2. I don't think that I am constructing the rows, columns, and fields correctly.

Any information you have or sites that could help me would be great! Thanks in advance,

Josh
Nov 12, 2009 at 5:30am
Do you know the difference between passing variables by value and passing them by reference ??
Topic archived. No new replies allowed.