WARNING!! this code is hefty so i cut out cases 2-5 to fit it in before i cut the cases out it was 20,000 character and its still not done yet. It is the same code as other cases for the switch(from) just diffrernt conversion formulas.And it is ackward because of this scrren. A thing that will help is to copy to compiler.(i used dev)
ok. thats the "warning". Can u please review the code i mean for basis of working. Especially the goto's because i just implemented them after i forgot to put defaults. I did sorta comment so peeps can know what i plan. AND before andbody saya so. i will get rid of this usless code by putting them all into seperate function.
#include<iostream>//headers
#include<cstdlib>
usingnamespace std;//for cin,cout,endl..etc.
int main(){//man function
longdouble answer;//initializing variable for numbers
longdouble number;
int from;
int to;
char loop='y';// loop var
int loop_error;
do
{
system("CLS");
menu:
cout << "Welcome to Measurment System Converter" << endl;
cout << "Convert from the following:" << endl;
cout << "inches[1] centimeters[2] millimeters[3]" << endl;//shows option
cout << "feet[4] yards[5] kilometers[6] miles[7]" <<endl;
cout << "Enter the corresponding number: ";
cin >> from;//ask which option
system("CLS");
switch(from) //switch case for each number of choices earlier
{
case 1:
redo:
cout << "Convert to the following:" << endl;
cout << "centimeters[1] millimeters[2]" << endl;
cout << "feet[3] yards[4] kilometers[5] miles[6]" <<endl;//what to convert to
cout << "Enter the corresponding number: ";
cin >> to;// asked what convert to
switch(to)// switch case for what unit to convert too(last switch case)
{
case 1 :
cout << "Type in an amount of inches to convert to centimeters: ";
cin >> number;//ask amount of inches to convert
answer = number * 2.54;//conversion eqaution
cout << endl << number << " converted to centimeters equals: " << answer;//answer
cout << endl << "Would you like to try again? [y/n]: ";
cin >> loop;//try again loop
break;
case 2 :
cout << "Type in an amount of inches to convert to millimeters: ";
cin >> number;// ask amount of mm to convert
answer = number * 25.4;//eqaution
cout << endl << number << " converted to millimeters equals: " << answer;//answer
cout << endl << "Would you like to try again? [y/n]: ";//try again loop
cin >> loop;
break;
case 3 :
cout << "Type in an amount of inches to convert to feet: ";
cin >> number;// ask amount of mm to convert
answer = number / 12;//eqaution
cout << endl << number << " converted to feet equals: " << answer;//answer
cout << endl << "Would you like to try again? [y/n]: ";//try again loop
cin >> loop;//comments after this are redundant
break;
case 4 :
cout << "Type in an amount of inches to convert to yards: ";
cin >> number;
answer = number / 36;
cout << endl << number << " converted to yards equals: " << answer;
cout << endl << "Would you like to try again? [y/n]: ";
cin >> loop;
break;
case 5 :
cout << "Type in an amount of inches to convert to kilometers: ";
cin >> number;
answer = number * 0.0254 ;
cout << endl << number << " converted to kilometers equals: " << answer;
cout << endl << "Would you like to try again? [y/n]: ";
cin >> loop;
break;
case 6 :
cout << "Type in an amount of inches to convert to miles: ";
cin >> number;
answer = number * 0.000016 ;
cout << endl << number << " converted to miles equals: " << answer;
cout << endl << "Would you like to try again? [y/n]: ";
cin >> loop;
break;
default://if anything except a number is typed
cout << "I am sorry but your choice is invalid" << endl;
cout << "If you would like to revise your choice press [1]" << endl;
cout << "If you would like to quit press [2]"<<endl;
cout << "Enter Here: ";
cin << loop_error;//chose 1 or 2
switch(loop_error)
{
case 1: //revise choice goes back to last choice
goto redo;
break;
case 2://quit by returning 0(terminate program)
return -1;
break;
default:/* if they put in something stupid again, screw them(or send
them back to the first menu*/
cout << "You will be redirected to the main menu..."<< endl;
system("PAUSE")
goto menu;
break;
} //close default switch
break;
}//closes switch(to)
break;
case 6:// didnt do yet following are the same as before just diffrernt formulas
break;
case 7:
break;
default :
break;
}// closing bracket for switch(from)
} while (loop == 'y' || loop == 'Y');// while loop for the try again option(and closing bracket for do)
return 0;// return 0 to end program
} //closing for int main
ok thats it. once again i apoligize for how the code looks because of the size of he windwo.