Okay I have tried everything to alter the code but nothing works, so I ask for your help.

The thing is I am trying to turn my code from this:

*______*
**____**
***__***
********
***__***
**____**
*______*

into this:

*________*
**______**
***____***
**********
***_**_***
**__**__**
*___**___*
____**
____**
____**
____**
____**

Replacing the underscores with spaces.

The side being depended on the entered number and the middle always being 10 by 2, so here is my code please help me alter it:

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

const char symbol('*');                                      
const char space(' ');

int main(int argc, char *argv[]){
     string in;                                              
     stringstream ss;
     int n, x;
     x=1;                                                    

     do {                                                    
         cout << "Enter an integer(an odd number): ";
         getline(cin,in);                                    
         ss.clear();                                         
         ss.str(in);                                         
     } while (!(ss >> n) || (n < 3) || (!(n & 1)));          

     char *symbols = new char[n + 1], *p = symbols + n - 1,   it
          *spaces = new char[(n * 2) - 1], *q = spaces;
     fill(symbols, symbols + n, symbol);                     
     symbols[n] = '\0';                                      
     fill(spaces, spaces + (n * 2) - 2, space);
     spaces[(n * 2) - 1] = '\0';

     do {
         cout << p << q << p << endl;                       
         if (p == symbols) x = -x;                           
         p -= x; q += 2*x;
     } while (q >= spaces);




     system("PAUSE");
     return EXIT_SUCCESS;
}

The thing is I am trying to turn my code from this:

*______*
**____**
***__***
********
***__***
**____**
*______*

into this:

*________*
**______**
***____***
**********
***_**_***
**__**__**
*___**___*
____**
____**
____**
____**
____**

Replacing the underscores with spaces.

The side being depended on the entered number and the middle always being 10 by 2, so here is my code please help me alter it:

#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>

using namespace std;

const char symbol('*');                                      
const char space(' ');

int main(int argc, char *argv[]){
     string in;                                              
     stringstream ss;
     int n, x;
     x=1;                                                    
     
     do {                                                    
         cout << "Enter an integer(an odd number): ";
         getline(cin,in);                                    
         ss.clear();                                         
         ss.str(in);                                         
     } while (!(ss >> n) || (n < 3) || (!(n & 1)));          
     
     char *symbols = new char[n + 1], *p = symbols + n - 1,   it
          *spaces = new char[(n * 2) - 1], *q = spaces;
     fill(symbols, symbols + n, symbol);                     
     symbols[n] = '\0';                                      
     fill(spaces, spaces + (n * 2) - 2, space);
     spaces[(n * 2) - 1] = '\0';
     
     do {
         cout << p << q << p << endl;                       
         if (p == symbols) x = -x;                           
         p -= x; q += 2*x;
     } while (q >= spaces);

    


     system("PAUSE");
     return EXIT_SUCCESS;
}

I don't think I'd try to convert anything. I think I'd start again from scratch. It might be faster.

I'm a big fan of doing some nice simple nested loops with if statements in there. Print a character at a time. I think having character strings and displaying them just makes it harder.

So you have a bunch of lines. Each line has this:

  1. Display 0 or more asterisks.
  2. Display 0 or more spaces.
  3. Display 0 or more asterisks.
  4. Display 0 or more spaces.
  5. Display 0 or more asterisks.
  6. Display a newline.

So it's a loop with a bunch of for loops inside it and you do some fairly simple math to decide what the loop constraints are.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.