0

I hav this code below.How can i use Macros , so that i can change at random "-" and " " without searching through the codes?

#include <iostream>

using namespace std;

int main()
{
   int row,col,n;
   cout<<"Enter an Integer number:\n";
   cin>> n;

   cout<<("Numerical Pattern\n");
   for ( row = 1 ; row <=n ; row++ )
   {
   for ( col=1; col <= row ; col++ )
   {
      if(col==row)
      {
         cout<<"-";
   }
      else
      {
         cout<<" ";
      }
   }

    cout<<endl;   
   }

    return(EXIT_SUCCESS);

}

Edited by deceptikon: Moved to C++

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by deceptikon
0
#include <iostream>

using namespace std;

#define PATTERN   "-"
#define SEPARATOR " "

int main()
{
   int row,col,n;
   cout<<"Enter an Integer number:\n";
   cin>> n;

   cout<<("Numerical Pattern\n");
   for ( row = 1 ; row <=n ; row++ )
   {
       for ( col=1; col <= row ; col++ )
       {
          if(col==row)
          {
             cout<< PATTERN;
          }
          else
          {
             cout<< SEPARATOR;
          }
       }

       cout<<endl;   
   }

   return(EXIT_SUCCESS);
}

Edited by deceptikon

This topic has been dead for over six months. 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.