spaces in setfill?

Elite Diviner
Joined
Oct 10, 2005
Messages
453
Reaction score
0
#include <iostream>
#include <iomanip>
using namespace std;

int main () {
int x, z;

for ( int y = 0; y < 1; y++ )
{

for ( int x = 0; x < 9; x++ )
{
z=x+1;

cout << setfill ('#') <<setw (z)<<" "<<"0"<< endl;

**
**
**
Output is
0
# 0
## 0
### 0
#### 0
##### 0
###### 0
####### 0
######## 0
Press any key to continue


The out put i want is.
0

# 0

# # 0

# # # 0

# # # # 0

# # # # # 0

# # # # # # 0

How do u put Spaces between # >.< it has to be nested For loop too... i can do vertical spacing but not spaces between #.... forgot how and been trying to find out how anyone can explain i think its simple just i cant lol.. i know this code is noobish... just trying to get an example to work while i study for some cheap test. Teacher is horrible.......... we have not had lab for like 2 months and she expects us to know how to do guis and stuff already.
 
you tried setfill as to chars instead of one, hash and space?

I got it to work

int main()
{
int x, z;
for ( int y = 0; y < 1; y++ )
{
for ( int x = -2; x < 9; x++ )
{
if (x != -2)
{
z=x+1;
for (int r = 0; r < z; r++)
{
cout << setfill ('#')<<setw (2)<<" ";
**
cout << setfill ('#')<<setw (2)<<" "<<"0"<< endl;
**
else
{
cout <<"0"<< endl;
**
**
**
system("PAUSE");
return EXIT_SUCCESS;
**
 
Last edited:
First of all there is no point in nesting a for loop if its only executing once. Secondly this setfill thing will not work, because you cant Split and add spaces in the middle, instead, it should look like this:

Code:
#include <iostream>
#include <iomanip>
using namespace std;

int main () 
{
    int counter = 0;
    for ( int y = 0; y < 9 ; y++ ) 
    {
        for ( int x = 0; x < 8 ; x++ ) 
         {
            if(x < counter )
            {
              cout << "# " ;
            **
         **
        cout << "0\n";
        counter++;
    **
    return 0;
**

Your Welcome. Note: iomanip may not be needed if this is all you need.

(Also since this is RageZone code script.. ** = the closing curly brace braket)
 
ty my teacher is anoying she has not been teaching for 10 years and she kills us with work and no lab time =/
 
Back