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.
#include <iomanip>
#include <iostream>
#include <string>
usingnamespace 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)
{
}
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);
#include <iomanip>
#include <iostream>
#include <string>
usingnamespace 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()
{
}
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.
#include <iostream>
usingnamespace 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
}
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.
#include <iostream>
#include <iomanip>
usingnamespace 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;
}
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.