0

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 << " ";
             }
         }
     }
}
3
Contributors
4
Replies
5
Views
9 Years
Discussion Span
Last Post by Salem
0

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

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

The code is just fine

0

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

0

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

0

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

Each function does ONE job properly.

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.