The examples of this page have basic comments and not all the comments.. They are written to be studed not to be used.

Examples:
Basics
Control structures
Example 1
Other structures

Example 1
The first example is the calculation of the a^n. It is simple and his power is the for expresion.

//start of the programm
#include iostream.h  //the files we need
#include conio.h   //the files with *.h must be between <>
#include iomanip.h
void main()
{
float a,n,i;   //we define 4 variables , 3 as float and 1 as long
long d;
clrscr();   //we call this function to clear the screen
cout<<"Give the base of the power : ";   //we prompt the message in the " "
cin>>a;   //the computer wait so we give the base
cout<<"Give the power : ";
cin>>n;   //here we give the power
d=1;   //we put initial value to this variable
for (i=1;i<=n;i++)   //start of the loop
{
d*=a;   //here is the key!
}
cout<//here is the prompt of the correct calculation

getch();   //this function wait so we have to hit a key before the program ends
}   //end of the main function

Tsamantero , [email protected] , C++ Examples
Time to go home?
Back to main page