Let us Learn how to create a loading Screen in C++.
Firstly I would like to tell you that it works on simple and logical loops.
Also the outputs like :
- Creating Temporary files
- Accessing Main Memory
- Accessing Cache
are also based on the counter in these loops.
The outer loop starts from 1 goes till 50. the reason for taking the end point as 50 is that in the inner loop the counter has been used to determine the % loaded and the variable is multiplied by 2.
The delay function is used so as to make the loading screen look realistic by making it faster as the loading % increases. The formula derived in it is based on the output statement being used ie cout<<"ASCII 219";. You can do it by pressing and holding the left Ctrl key an typing 219 and leaving the key.
So here is the Source Code:
#include<iostream.h>
#include<conio.h>
#include<dos.h>
void main()
{
clrscr();
for(int i=1;i<=50;i++)
{ clrscr();
cout<<"\n\n\n\n\t\t\t\t Loading "<<'\n'<<'\t'<<'\t';
for(int j=1;j<=i;j++)
cout<<"²";
cout<<"\n\n\t "<<2*i<<"%";
if( i > 1 && i < 20)
cout<<"\n\n\tCreating Temporary files";
else if( i > 20 && i<40)
cout<<"\n\n\tAccessing Main Memory";
else if(i >40 && i<48)
cout<<"\n\n\tAccessing Cache";
else cout<<"\n\n\tComplete. Press Enter to Continue ";
delay(150 - i*3);
}
getch();
}So basically there are 2 loops, the outer and the inner.
The outer loop starts from 1 goes till 50. the reason for taking the end point as 50 is that in the inner loop the counter has been used to determine the % loaded and the variable is multiplied by 2.
The delay function is used so as to make the loading screen look realistic by making it faster as the loading % increases. The formula derived in it is based on the output statement being used ie cout<<"ASCII 219";. You can do it by pressing and holding the left Ctrl key an typing 219 and leaving the key.
On code blocks don't working
ReplyDeletecan you mail me the code file at r.sachdev1111@gmail.com
Deletedelay is not declared, how can it be working?
ReplyDeleteMake sure that you have included dos.h
Deletei did it.. but, its still not declared.
Deletei wrote it on DevC++