C++ | Volume conversion

Introduction

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.
  2. Add void main.
  3. Start program by first clearing the screen.
  4. Declare the variables as float (name them as you want.)
  5. Add cout and cin of variables you want to convert from.(as shown in program)
  6. Convert the Volume from variable and save them in one variable.
  7. Cout the converted Volume variable.

At the end

You learnt creating the c++ program of conversion of Volume from one unit to other unit. So now enjoy the program.

Please comment on the post and share it.
And like it if you liked.

Advertisements

2 thoughts on “C++ | Volume conversion

  1. Hi, I’m glad to find someone who has the same interests.!!!
    I’m junior developer and i like your blog, hope you’ll make more tutorial 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s