Thread: Creating a diamond pattern

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2008
    Posts
    11

    Creating a diamond pattern

    Hello everyone,

    I am attempting to create a diamond pattern, and failing miserably. I am looking for some info on getting my proggie running

    Each dash represents a space. It is supposed to be monospace. Notice it goes 1-3-5-3-1. Here is an example of it working:
    ----x
    --xxx
    xxxxx
    --xxx
    ----x

    I know I need a few "for" loops. Outer for counting spaces and inner couple for counting and displaying spaces and numbers.
    Here's what I have so far...

    NEW CODE ADDED.
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    int main() {
        int num;
      char character;
      cout << "Enter Number: ";
      cin >> num;
      
    int half=(num/2);
    cout <<half<<endl;
    
      while (num>0){ 
      cout << "Enter character: "<<endl;
      cin >> character;
      cout <<endl;
    
      for (int row=0;row<num;++row) {
          int numplus1=num++;
    
          for (int space=((numplus1/2)-row);space<=row;++space){  
              cout <<" ";
              cout <<endl;
          for (int display=num-((numplus1)-(2*row));display<=num;display++){
              cout <<character;
              cout <<endl;
          }}
          for (int space=((numplus1/2)-row);space<=row;++space){ 
              cout <<" ";
              cout <<endl;
          for (int display=num-((numplus1)-(2*row));display<=num;display++){
               cout <<character;
               cout <<endl;
          }}
        cout << "\nEnter Number: ";
      cin >> num;
    }
      cout <<endl;
      cout << "Bye"<<endl;
      system("PAUSE");
      return 0;}
    }
    Last edited by ___________; 07-15-2008 at 02:30 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  2. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 04:07 AM
  3. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  4. Creating Patterns
    By incognito in forum Game Programming
    Replies: 5
    Last Post: 03-16-2003, 09:02 AM
  5. text pattern recognition
    By mtsmox in forum C++ Programming
    Replies: 5
    Last Post: 02-27-2002, 08:38 AM