i have here this constructor used 2 display a bitmap

void bitmap::display() const
{
     for (int r = 0; r < numrows; r++)
     {
         for (int c = 0; c < numcols; c++)
         {
             if (grid[r][c] == 0)
             cout << " " ;
             
             else cout << "*";
         }
         cout << endl;
             
          
     }
     
}

i have here this invert function which is meant to make the 0's into 1's and the * into " " but it is not working proply can ne1 help me

void bitmap::invert()
{
     for (int r = 0; r < numrows; r++)
     {
         for (int c = 0; c < numcols; c++)
         {
             if (grid[r][c] = 1)
             {
             grid[r][c] = 0;
             cout << "*";
             }
             else{
             grid[r][c] = 1;
            cout << " ";
             }
         }
     }
}

Its a simple mistake.
if (grid[r][c] = 1)

= is an assinment operator. == is the relational operator

The code is just fine

i did that but the invert still doesnt work it displays, but the *'s and ' 's are all really far apart

I dont have much code to deal with, besides the constructor displays a '*' if mat element is 1 & the invert function does the same, even though it changes the matrix. Upload more code

Why does invert() also display the result?
Shouldn't you just call display() when you're done?

Each function does ONE job properly.

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.