How to delete spacing after row is complete in c++?

Viewed 58

I have been working on a project. I am limited to using a few libraries so any additional library would not be helpful. So far my project works, but I am noticing an extra space after the last row is completed. How do I fix this extra spacing issue? please help! There's a space at the bottom... and this only seems to happen when the last row is full and no date is carried over.

// Extracted.. 
#include <iostream>

         if (day >= 9)
         {
            std::cout << day;
         }
         else
         {
          std::cout << day << " ";
         }
         if (day != days_per)
         {
          std::cout << " ";
         }
         }
2 Answers

I think this will fix it:

  • That's the block dealing with the last day of the week (Saturday).
  • Print it always.
  • If it is the last day of the month, don't do anything else.
  • Otherwise: 1) print a newline, and 2) if the next day has 1 digit (current day < 9), print a space.

[Demo]

      if (++count > 6)
      {
         count = 0;
         std::cout << day;
         if (day != days_per)
         {
            std::cout << '\n';
            if (day < 9)
            {
                std::cout << " ";
            }
         }
      }

you dont need to delete anything, just dont produce it. Your probelm is here

         if (day >= 9)
        {
            std::cout << day << '\n';
        }
        else
        {
            std::cout << day << '\n' << " ";
        }

when you come to the end of a line you do a line feed if even it was the last day.

change to

     if (day >= 9)
     {
        std::cout << day;
        if (day != days_per) std::cout << '\n';
     }
     else
     {
        std::cout << day << '\n' << " ";
     }

you dont need it on the other path because thats never hit at the end of the month (day is alwasy 2 digits)

Related