 # Techtopz

(@techtopz)

Techtopz is a blog on programming and tech stuff.
Techtopz is now on UpHub.

# C++ | Volume conversion

This Program will let you convert Volume from one unit to other unit. The first Program will convert Meter cube to Centimeter cube. The second one lets you convert Meter cube to Feet cube. The next will convert Meter cube to Litre. The Last program will convert Meter cube to Gallon (UK). So you can make more programs by using more units for conversion of volume by just modifying the conversion formula. Go enjoy the program. Lets begin…

Program to convert Meter cube to Centimeter cube

``````#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the Volume in given unit save them in 'a'
cout<<"Enter the Volume in Meter cube"<<endl;
cin>>a;
//convert and save it in 'b'
b=a*1000000;
//show the output 'b'
cout<<"Volume in Centimeter cube is "<<b;
//get character
getch();
}
``````

Output

Enter the Volume in Meter cube
2
Volume in Centimeter cube is 2000000

Program to convert Meter cube to Feet cube

``````#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the Volume in given unit save them in 'a'
cout<<"Enter the Volume in Meter cube"<<endl;
cin>>a;
//convert and save it in 'b'
b=a*35.32;
//show the output 'b'
cout<<"Volume in Feet cube is "<<b;
//get character
getch();
}
``````

Output

Enter the Volume in Meter cube
2
Volume in Feet cube is 70.64

Program to convert Meter cube to Litre

``````#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the Volume in given unit save them in 'a'
cout<<"Enter the Volume in Meter cube"<<endl;
cin>>a;
//convert and save it in 'b'
b=a*1000;
//show the output 'b'
cout<<"Volume in Litre is "<<b;
//get character
getch();
}
``````

Output

Enter the Volume in Meter cube
2.6
Volume in Litre is 2600

Program to convert Meter cube to Gallon (UK)

``````#include<iostream.h>
#include<conio.h>
void main()
{
//clear the screen.
clrscr();
//declare variable type float
float a,b;
//Input the Volume in given unit save them in 'a'
cout<<"Enter the Volume in Meter cube"<<endl;
cin>>a;
//convert and save it in 'b'
b=a*220;
//show the output 'b'
cout<<"Volume in Gallon (UK) is "<<b;
//get character
getch();
}
``````

Output

Enter the Volume in Meter cube
45
Volume in Gallon (UK) is 9900

How does it work
1. You enter the volume in given unit and is saved in variable ‘a’.
2. The volume is converted according to conversion formula and is saved in ‘b’.
3. Variable ‘b’ is shown by cout.

Extending it
The Program can be extended by adding more unit to conversion and by adding their Conversion formula for other unit and more variables can be added to program to convert multiple volumes. Like wise you can also use following unit for conversion :
- Centimeter cube.
- Meter cube.
- Feet cube.
- Gallon (UK).
- Gallon (US).
- Inch cube.
- Litre.
- Yard cube.

Explanation
1. Include ‘iostream.h’ and ‘conio.h’ files.