You are on page 1of 3

SYSTEM PAUSE;

People use System("PAUSE") because they want the program to wait until they hit enter to
they can see their output.
GETCHAR
It can pause a program for a certain period of time. It only takes a character,
getchar();
GOTO FUNCTION
It is used to reach the top position where we are required to reach.
Check:



gotocheck;
GETLINE FUNCTION
This is used to print full sentences and also prints spaces between words.
String a;
getline(cin,a);

Power Function
It is used to get the power of certain number. Include <cmath> first.
int a,b,c;//a is base and b is exponent
cin>>a;
cin>>b;
c=pow(a,b);
cout<<"ans: "<<(2*c)<<endl;

Rand Function
It basically generates a random number in our program.
For this we have to declare two additional libraries along with <iostream>. So include <cstdlib>
and <ctime>.
#include<iostream>
#include<cstdlib>
#include<ctime>
using namespace std;
int main ()
{
srand(time(0)); // by this function we access time of the PC and generate a random
……………………………..number every time. IF WE USE SIMPLE srand(45) WITH ANY
INPUT ……………………………..IT WILL ALWAYS GIVE YOU REPEATED NUMBERS.
for (int i=0;i<1;i++)
{
cout<<1+(rand()%6)<<endl; //if you want a number between 1 and 6 we have to use
………………………………………….// mode and then add 1 to the answer
}
}

Sizeof Function :
This function tells us the size of the data type being used in our code. It tells us in “ bytes ”. E.g
#include<iostream>
using namespace std;
int main ()
{

char a;
int b;
float c;
double d;
cout<<"Character : "<<sizeof(a)<<endl;
cout<<"Integar : "<<sizeof(b)<<endl;
cout<<"Float : "<<sizeof(c)<<endl;
cout<<"Double : "<<sizeof(d)<<endl;
system("pause");
}

It can also be used to find the number of elements used in an array,


#include<iostream>
using namespace std;
int main ()
{
double d[10];

cout<<"Double : "<<sizeof(d)<<endl;
cout<<"Array has "<<sizeof(d)/sizeof(d[0])<<" elements "<<endl; //or divide it by 8
system("pause");
}
Sleep Function:
In order to put delay in the program we often use the following sleep function. Following
liabraries are necessary to compile it. Windows.h is required and then
Sleep(no of milli sec);
// if you want to sleep for 1sec sleep argument is 1000//milli sec

#include<string>
#include<iostream>
#include<Windows.h>
using namespace std;
int main ()
{
cout<<"End of Level"<<endl;
cout<<"Loading"<<endl;
Sleep(0700);
cout<<".";
Sleep(0700);
cout<<".";
Sleep(0700);
cout<<".";
Sleep(0700);
cout<<"\n Next Level\n"<<endl;
system("cls");
return 0;
}

Clear Screen:
It clears the screen of the console. Just write
System(“cls”);

You might also like