Loading problems

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <iostream>
#include <conio.h>
#include <windows.h>
using namespace std;

int n;
main()
{
      cout<<"Loading....";
      for (n=1; n<100; n++)
      {
          cout<<n;
          cout<<"\b";
          Sleep(200);
          if (n>9)
          {
                  cout<<n;
                  cout<<"\b\b";
                  Sleep(200);
          }
          
      }

      getch();
}

I'm getting a problem on my final output it should only be "Loading..."
but my compiler shows. "Loading...1111111111222222222233333333333444444444555555555566666666667777777777888888888899999999999"
closed account (o3hC5Di1)
Hi there,

You are outputting the number on line 12 and 17, if you don't want them to appear, delete those lines.
It appears as one line because you're not printing any linebreaks, so everything is put one after the other.

Hope that helps.

All the best,
NwN
Last edited on
Declare a clearscreen function (there is a lot of talk discussing this one around here), then
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void LoadScreen(int length)
{
  for(int i=0; i<length, i++)
  {
    cout<<"Loading.";
    sleep(200);
    ClearScreen();//yours may have a different name
    cout<<"Loading..";
    sleep(200);
    ClearScreen();//yours may have a different name
    cout<<"Loading...";
    sleep(200);
    ClearScreen();
  }
}
Thanks for the fast replies. Now I figured out what is wrong in my code. I placed line 12-14 in an else statement.
Topic archived. No new replies allowed.