Need hint for this, please!

So our assignment is to do this:

The following program (see file starBox.txt) is the shell of a program that displays the border of a box of starts of size n by n/2 on the screen monitor, where n is a positive integer number. For example, if n is 11, the following box is displayed:

***********
* *
* *
* *
***********

Its suppose to form a box with the chosen symbol.
However, my code is reporting this problem.

error C2660: 'displayStarBox': function does not take 0 arguments
I don't get what is wrong.
This is my code.
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

#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

void  displayStarBox(int);

int main()
{
	int  number;
	string symbol;
	int t = 0;
	int b = 0;
	int ls = 0;
	int rs = 0;
	displayStarBox();
	cout << "Enter the number of stars for the top; Enter 0 to quit " << endl;
	cin >> number;

	while (number > 0)  // this loops allows user to display more than one box of different sizes
	{
		cout << endl << "The chosen symbol to build your quadrilateral " << endl;

		cin >> symbol;
	}
	//top
	while (t <= number)
	{
		cout << symbol << endl;
		t++;
	}
//leftside
	while (ls <= number)
	{
		cout <<  symbol << setw(number) << endl;
	}
//right side
	while (rs <= number)
	{
		cout << symbol << setw(number) << endl;
	}

	//bottom
	while (b <= number)
	{
		cout << symbol << endl;
		b++;
	}
	system("pause");
	return 0;




}





void  displayStarBox(int n)

{


}
Last edited on
At line 62 you declare displayStarBox as taking a single integer as a parameter. So whenever you call the function you must give it an intenger i.e.displayStarBox(45);
So I changed it. But it just prints out and asks the questions about the number and the symbol. Any help with that?

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
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

void  displayStarBox();

int main()
{
	int  number;
	string symbol;
	int t = 0;
	int b = 0;
	int ls = 0;
	int rs = 0;
	displayStarBox();
	cout << "Enter the number of stars for the top; Enter 0 to quit " << endl;
	cin >> number;

	while (number > 0)  // this loops allows user to display more than one box of different sizes
	{
		cout << endl << "The chosen symbol to build your quadrilateral " << endl;

		cin >> symbol;
	}
	//top
	while (t <= number)
	{
		cout << symbol << endl;
		t++;
	}
	while (ls <= number)
	{
		cout <<  symbol << setw(number/2) << endl;
	}

	while (rs <= number)
	{
		cout << symbol << setw(number/2) << endl;
	}

	//bottom
	while (b <= number)
	{
		cout << symbol << endl;
		b++;
	}
	system("pause");
	return 0;




}


void  displayStarBox()

{
}
I don't get what is wrong.

I don't get what is right!


What do you think the purpose of a function with the name "displayStarBox" might be?

@Too Explosive was right - you should call this function with the parameter n ... not remove all parameters from it as you have just done.

It is the function displayStarBox( n ) which will draw the box, not the main routine.


Very roughly ...
- Ask the user for n
- THEN call displayStarBox( n );
- ... and THAT FUNCTION will then draw the box.


Although there are many different ways of drawing a box, your teacher is probably expecting you to use loops.

Start with just using *, (which, incidentally, is a char, not a string). You can extend the program to vary the character symbol later, once you get that working. Similarly with drawing multiple boxes.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;

void displayStarBox( int n );



int main()
{
   int n;
   cout << "Enter the number of stars for the top: " << endl;
   cin >> n;
   displayStarBox( n );                // Call it with n as a parameter
}



void displayStarBox( int n )
{
   cout << "In the routine displayStarBox with parameter " << n << endl;
   cout << "Now to write some code to draw a box of that size" << endl;

   // Your box-drawing code goes here
}
Last edited on
Okay so since it was all wrong I restarted it but without the void displayStarBox.
I need help in formatting it to actually look like a box. I got the left and top side it's just the spacing with the right and bottom side that are giving me problems.
Right now I'm just setting the symbol to * instead of having it inputted.

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
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{

	int  number;
	cout << endl << "Enter the number of stars for the top; Enter 0 to quit " << endl;

		cin >> number;
	
	while (number > 0)  // this loops allows user to display more than one box of different sizes
	{
		/* WRITE call to displayStarBox() */

		cout << endl << "Enter the number of stars for the top; Enter 0 to quit " << endl;

		cin >> number;

		//top

		for (int t = 0; t < number; t++)
		{
			cout << " *";

		}

		for (int ls = 0; ls < (number/2 - 1); ls++)
		{
			
			cout << "\n *" << setw(number) << "  *";

		}
		for (int b = 0; b < (number - 2); b++)
		{

			cout << "* ";
		}
		
		


	}
	system("pause");
	return 0;
}

@BGA6444,

I thought that my code template was straightforward to follow. You would be better calling a function to draw a box. I really suggest that you go back to that.

You are making your code unnecessarily difficult for yourself. If you actually walk through what will happen when you run it then you will see the problems. Here are some suggestions.

- Just draw ONE box. You can come back to looping that bit later. You will also avoid prompting twice.

- Don't include the extra space in your output - just output sets of "*", not with the preceding space, " *". This will make it much easier to calculate the necessary widths.

- Doing an end-of-line line feed as the start of a looping item is completely counter-intuitive. Either put it at the end or, better, separate it off into a separate cout statement. You aren't doing the necessary line feed before the bottom of the box.

I'm not going to correct your code as it stands - the structure is not good.
Last edited on
I figured it out using my code the way it was, thank you though.
Topic archived. No new replies allowed.