Advertisement
Sajgoniarz

Console Progress Bar snippet

Jul 13th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. // x - step,n - count of iterations, w - screen width
  2. static inline void loadbar(unsigned int x, unsigned int n, unsigned int w = 50)
  3. {
  4.     if ((x != n) && (x % (n / 100 + 1) != 0)) return;
  5.  
  6.     float ratio = x / (float)n;
  7.     int   c = ratio * w;
  8.  
  9.     printf("%u %%[",(int)(ratio * 100));
  10.     for (int x = 0; x<c; x++) std::cout << "=";
  11.     for (int x = c; x<w; x++) std::cout << " ";
  12.     std::cout << "]\r" << std::flush;
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement