0

I have been working on this program for about a week and i have been getting these errors that i just cant get by. The program is supposed to first accept user input for the type of symbol. Then its supposed to accept user input for a number. Finally it is supposed to output a square made up of the character chosen by the user and with a length chosen by the users number input. This is what i have but it has been giving me errors.

#include <iostream>
using namespace std;
void buildSquare(int);
int main()
{
	int symbol, length, side;
	
	cout << " Please enter symbol to fill square" << endl;
	cin >> symbol >> endl;
	cout << " Please enter length of sides. "<< endl;
	cin >> length >> endl;
	buildSquare( length);

return 0;
}

void buildSquare( int length){

	for(int side = 0; side < length; side++)
	{
		cout << symbol;
	}
	cout << endl;
}

Please any help would be greatly appreciated. Thank you in advance

3
Contributors
11
Replies
12
Views
6 Years
Discussion Span
Last Post by sosongetsu
0

To start, you can't use endl in cin, use it only for cout, cin automatically moves you to newline. And remembr to pass symbol argument other function :D

0

Wow thanks for the speedy response. I think i did what you said and it got my program to say run but when i run it, it only lets me put an input for the symbol not for the length. Here is my updated program.

#include <iostream>
using namespace std;
void buildSquare(int, int);
int main()
{
	int symbol, length, side;
	
	cout << " Please enter symbol to fill square" << endl;
	cin >> symbol;
	cout << " Please enter length of sides "<< endl;
	cin >> length;
	buildSquare( length, symbol);

return 0;
}

void buildSquare( int length, int symbol){

	for(int side = 0; side < length; side++)
	{
		cout << symbol;
	}
	cout << endl;

I am also getting an error saying "Project.exe not found or not built by the last incremental link; performing full link"

0

Ok you can't hold symbols using ints, so you need to change to char. Since it hold symbols and letters. Everything else can stay int. And you have to re-logic your loop in build square, you will see when you get there.

0

ok this is what i have now

#include <iostream>
using namespace std;
void buildSquare(int, char);
int main()
{
	int side, length;
	char symbol;
	
	cout << " Please enter symbol to fill square" << endl;
	cin >> symbol;
	cout << " Please enter length of sides "<< endl;
	cin >> length;
	buildSquare( length, symbol);

return 0;
}

void buildSquare( int length, char symbol){

	for(int side = 0; side < length; side++)
	{
		cout << symbol;
	}
	cout << endl;
}

now my output is isnt giving me the symbol i want as well as the number of symbols i input but only across. its creating a line not a square. How can i fix this?

0

im sorry for the typo. It is giving me the symbol i want as well as the number of symbols i want across but it is not doing the same vertically. Its creating a line instead of a square. How can i fix this.

0

The nested for loop is what you are looking for. You will use nested for loops once you get into array of arrays.

void buildSquare( int length, char symbol){
// Length = Length x Length to make the box
// Symbol will be used to make the box
// The for loop nested inside a for loop help creates 

            // this first for loop will be used for the vertical length of the box
	for(int side = 0; side < length; side++)
	{
         // this second for loop will be used to create the horizontal length of the box
            for(int side2 = 0; side2 < length; side2++){
		cout << symbol;
            }
            cout << endl;
	}
	
}

Edited by Saith: n/a

0

The nested for loop is what you are looking for. You will use nested for loops once you get into array of arrays.

void buildSquare( int length, char symbol){
// Length = Length x Length to make the box
// Symbol will be used to make the box
// The for loop nested inside a for loop help creates 

            // this first for loop will be used for the vertical length of the box
	for(int side = 0; side < length; side++)
	{
         // this second for loop will be used to create the horizontal length of the box
            for(int side2 = 0; side2 < length; side2++){
		cout << symbol;
            }
            cout << endl;
	}
	
}

Depends if he is looking for a solid square or the outline :D

0

Thank you both of you. Im glad their is a place with people so helpful. After all this time tinkering with this program its finally working. Thanks to you.

Saith i ended up using your idea for the end of my program as it worked out.

Nandomo thank you for getting me back on track in the first place. I was getting so upset trying to work out the errors i was getting that i was making weak mistakes. Both of you were incredibly helpful. Here is what i believe to be the finished program.

include <iostream>
using namespace std;
void buildSquare(int, char);
int main()
{
	int side, length;
	char symbol;
	
	cout << " Please enter symbol to fill square" << endl;
	cin >> symbol;
	cout << " Please enter length of sides "<< endl;
	cin >> length;
	buildSquare( length, symbol);

return 0;
}

void buildSquare( int length, char symbol){

	for (int side = 0; side < length; side++)
	{
		for( int side2 = 0; side2 < length; side2++){
			cout << symbol;
		}
		cout << endl;
	}
}
0

Ok :D

#include <iostream>
#include <iomanip>
#include <windows.h>

using namespace std;
void buildSquare(int, char);
int main()
{
	char symbol; 
    int length, side;
	
	cout << " Please enter symbol to fill square" << endl;
	cin >> symbol;
	cout << " Please enter length of sides: (Minumum of 3)"<< endl;
	cin >> length;
	buildSquare( length, symbol);
    
    endl(cout);
    cout << " Program will close automatically. " << endl;
    
    Sleep(4000);
    
return 0;
}

void buildSquare( int length, char symbol)
{
    endl(cout);
	for(int side = 0; side < length; side++)
	{
		cout << symbol;
	}
	endl(cout);
	for(int side = 0; side < length - 2; side++)
	{
		cout << symbol << setfill(' ') << setw(length - 2) << " "
        << symbol << endl;
	}
	for(int side = 0; side < length; side++)
	{
		cout << symbol;
	}
	
	cout << endl;
}

I made a copy also. Try it.

0

wow thats impressive. thanks for all the help im pretty sure that this is around the time i can mark this area as solved. Hopefully if i ever have a program that i just cant work out like this one i could turn to you again. Thanks again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.