-moz-user-select:none; -webkit-user-select:none; -khtml-user-select:none; -ms-user-select:none; user-select:none;

Wednesday 22 July 2015

Convertion of marlas into square feet

My aim is to implement C++ in our daily lives and for this purpose,today I am here with a very easy but interesting example of "switch" statement.This program will convert marlas being enterd by the user into square feet and square feet being enterd by the user into marlas.I have also used the concept of "goto" statement in this program.

Below is the source code of this program.

Source code


#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int choice;
float marlas,squarefeet;
x: //label
cout<<"\t"<<"\t"<<"MAIN MENU"<<"\t"<<"\t"<<endl<<endl;
cout<<"Press 1 for converting marlas into square feet."<<endl<<endl;
cout<<"Press 2 for converting square feet into marlas."<<endl<<endl;
cout<<"Enter your choice:";
cin>>choice;
cout<<endl;
switch(choice)
{
case 1:
cout<<"Enter the required marlas:";
cin>>marlas;
cout<<endl;
squarefeet=marlas*5399.21;
cout<<"The required square feet="<<squarefeet<<endl<<endl;
break;
case 2:
cout<<"Enter the required square feets:";
cin>>squarefeet;
cout<<endl;
marlas=squarefeet*0.0001;
cout<<"The required marlas="<<marlas<<endl<<endl;
break;
default:
cout<<"Invalid choice."<<endl;
}
goto x;
}

Output

convertion of marlas into square units

Explanation

As we know that the formula for converting marlas into square feet is as follows:

squarefeet=marlas*5399.21;

The formula for converting square feet into marlas is as follows:

marlas=squarefeet*0.0001;

The "goto" statement used in the program will repeat the menu again and again.

No comments:

Post a Comment