This is a simple program to convert miles, yards, feet, and inches appropriately. Everything intended for works but I feel my program is very redundant. How can I make it more efficient and less lines of code? I tried % but failed to find way to increment next values.
#include <iostream>
using namespace std;
//NO GLOBAL VARIABLES
int main()
{
int m, y, f, i;
int a, b, c;
cout << "Enter: ";
cin >> m >> y >> f >> i;
cout << "You enter: " << m << "miles " << y << "yards "<< f << "feet " << i << "inches " << endl;
cout << "Convert the distance" << endl;
// 2miles 1761yards 4feet 27inches
// = 3miles 2yards 3feet 3inches
//ensure mile is zero or positive
if(m<0)
{
return 0;
}
//yard to mile conversion
for(a=0; a<100; a++)
{
if(y<0)
{
return 0;
}
if(y>1760)
{
m++;
y -= 1760;
}
if(y==1760)
{
y = 0;
m++;
}
if(y<1760)
{
y = y;
}
}
//feet to yard conversion
for(b=0; b<100; b++)
{
if(f>3)
{
y++;
f -= 3;
}
if(f==3)
{
y++;
f= 0;
}
if(f<3)
{
f = f;
}
if(f<0)
{
return 0;
}
}
//inches to feet conversion
for(c=0; c<100; c++)
{
if(i>12)
{
f++;
i -= 12;
}
if(i==12)
{
f++;
i = 0;
}
if(i<0)
{
return 0;
}
}
cout << "After conversion: " << m << "miles " << y << "yards "<< f << "feet " << i << "inches" << endl;
return 0;
}