Friends,
I 've choosen distance converter as my project.Main theme of my project is to convert kilometer,feet,inches,centimeter into eachother.I 've initiated making program but got stuck and became unable to make program.please help me :(
I'm posting the code: CODE:1
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
void main()
{
float a;
char b[15];
char c[15];
cout<<"Enter the length:"<<endl;
cin>>a;
cout<<"Enter the unit of value:"<<endl;
cin>>b;
cout<<"Enter the unit in which you wana convert:"<<endl;
cin>>c;
if(b=="inches" && c=="feet")
cout<<"The converted value is: "<<a*0.0833<<endl;
if(b=="inches" && c=="centimeter")
cout<<"The converted value is: "<<a*2.54<<endl;
if(b=="inches" && c=="meter")
cout<<"The converted value is: "<<a*0.0254<<endl;
if(b=="inches" && c=="kilometer")
cout<<"The converted value is: "<<a*2.5E-05<<endl;
if(b=="inches" && c=="yard")
cout<<"The converted value is: "<<a*0.02778<<endl;
if(b=="inches" && c=="mile")
cout<<"The converted value is: "<<a*1.5E-05<<endl;
}
The code above is entirely not working for me though compiler giving no error.
cout<<"Enter the length:"<<endl;
cin>>a;
cout<<"Enter the unit of value:"<<endl;
cin>>b;
cout<<"Enter the unit in which you wana convert:"<<endl;
cin>>c;
if(strlen(b)==6 && strlen(c)==4)
cout<<"The converted value is: "<<a*0.0833<<endl;
if(strlen(b)==6 && strlen(c)==10)
cout<<"The converted value is: "<<a*2.54<<endl;
if(strlen(b)==6 && strlen(c)==5)
cout<<"The converted value is: "<<a*0.0254<<endl;
if(strlen(b)==6 && strlen(c)==9)
cout<<"The converted value is: "<<a*2.5E-05<<endl;
}
Problem here is this's the conversions of inches to other units .When i want to convert feet into other units then following ambiguity arises:
if(strlen(b)==6 && strlen(c)==4)
cout<<"The converted value is: "<<a*0.0833<<endl
if(strlen(b)==4 && strlen(c)==6)
cout<<"The converted value is: "<<a*12<<endl
Well, the first line is how you convert centimeters to other units:
a centimeter is 1.0 centimeter, 0.01 meters, 0.00001 kilometers.
The second line is how you convert meters to other units:
a meter is 100.0 centimeters, 1.0 meter, 0.001 kilometers.
The third line is how you convert kilometers to other units:
a kilometer is 100000.0 centimeters, 1000.0 meters, 1.0 kilometer.
When user chooses 2,1 (meters to centimeters) the multiplication operand for the conversion is convert[1][0] which is the number in second row and first column, which is 100.0.
If i want to include weight converter too in your program then what modifications should i do?
Like:
Enter type of value
Enter value
Enter current unit of value
Enter desired unit