| | |
outline of square
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Feb 2008
Posts: 25
Reputation:
Solved Threads: 0
I can make a box with a char quite easily where the user enters two values L, and W using a for loop
but I don't know how to make just the outline. I'm told there are 2 if else statements needed and I've nested my for loop. I don't know how to restrict in the if statement so it will loop char going across, then empty spaces followed by char, then last line gets printed, any help would be appreciated eeee
e e
eeee
for (int myHeight =1;myHeight < width; myHeight++)
{
for (int myBase=1;myBase<length;myBase++)
{
cout <<c;
}
}
but I don't know how to make just the outline. I'm told there are 2 if else statements needed and I've nested my for loop. I don't know how to restrict in the if statement so it will loop char going across, then empty spaces followed by char, then last line gets printed, any help would be appreciated eeee
e e
eeee
for (int myHeight =1;myHeight < width; myHeight++)
{
for (int myBase=1;myBase<length;myBase++)
{
cout <<c;
}
}
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
So you want to do something like this?
but don't know how? Or you want this?
but it ends up like this?
Can you elaborate please? I'm not sure what you are trying to do.
C++ Syntax (Toggle Plain Text)
eeeeeeeeeeeeeeeee e e e e e e eeeeeeeeeeeeeeeee
C++ Syntax (Toggle Plain Text)
eeeeeee e e e e e e eeeeeee
C++ Syntax (Toggle Plain Text)
eeeeeee eee eee eeeeeee
use:
c Syntax (Toggle Plain Text)
for (int myHeight =1;myHeight <width; myHeight++) { for (int myBase=1;myBase<length;myBase++) { if(myBase==1 || myBase==length-1 ) printf(c); else if(myHeight==1 || myHeight==width-1) printf(c); else printf(" "); } printf("\n"); }
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
Did you try to incorporate any of DangerDev's code? Some of the lines using "printf" had problems, but when fixed, yielded a box that lined up for me. You could either change the "printf" statements to make them work or simply convert the "printf" statements to "cout" statements.
You say you "get too many spaces". In your original code that you posted I don't see you displaying any spaces at all. I am assuming that in this line:
c represents a character and that c is not a space. Please let us know whether you have gotten this working and, if not, please post some updated code.
You say you "get too many spaces". In your original code that you posted I don't see you displaying any spaces at all. I am assuming that in this line:
c++ Syntax (Toggle Plain Text)
cout << c;
It is very big mistake to write Correct is .
Remember the definition:
C++ Syntax (Toggle Plain Text)
printf(c);
C++ Syntax (Toggle Plain Text)
printf("%c", c);
Remember the definition:
C++ Syntax (Toggle Plain Text)
printf(argument, ...);
An Apple a Day keeps a Doctor away!
•
•
Join Date: Feb 2008
Posts: 25
Reputation:
Solved Threads: 0
for (int myHeight =0; myHeight< width-2; myHeight++)
{
cout << c;
}
for (int myHeight =0; myHeight< myHeight; myHeight++)
{
for (int myBase =0; myBase< width-2; myBase++)
{
cout << c;
cout << (" ");
}
cout << c;
}
for (int myHeight =0; myHeight< width; myHeight++)
{
cout << c;
cout << endl;
}
return 0;
}
this is what gives me only two sides of the box, I need a whole box
{
cout << c;
}
for (int myHeight =0; myHeight< myHeight; myHeight++)
{
for (int myBase =0; myBase< width-2; myBase++)
{
cout << c;
cout << (" ");
}
cout << c;
}
for (int myHeight =0; myHeight< width; myHeight++)
{
cout << c;
cout << endl;
}
return 0;
}
this is what gives me only two sides of the box, I need a whole box
•
•
Join Date: Jan 2008
Posts: 3,836
Reputation:
Solved Threads: 503
Look at this line. This loop will never be executed due to the condition you have imposed:
C++ Syntax (Toggle Plain Text)
myHeight < myHeight
![]() |
Similar Threads
- Windows XP loads to blank screen (Windows NT / 2000 / XP)
- memory management in wndows 2000 (Windows NT / 2000 / XP)
- Java Game Characteristics (Java)
- Java Game Characteristics (Java)
- Darts (Python)
- Thread tooltips (DaniWeb Community Feedback)
Other Threads in the C++ Forum
- Previous Thread: I can't find whats wrong with my Rot13 function?
- Next Thread: checking network connectivity?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






