cout << setw(10) <<" "<< " What conversion would you like to make?\n"; // menu
cout << setw(20) <<" "<< "1. km to m\n\n"; // make a choice which function to use.
cout << setw(20) <<" "<< "2. m to km\n\n";
cin >> choice;
switch(choice) // go to chosen function.
{
case 1 :
{
c_to_f();
break;
}
case 2 :
{
f_to_c();
break;
}
default :
{
cout << setw(10) <<" "<< "you must enter 1 or 2 "<< endl ; // validate and correct input of function choice.
}
}
cout << setw(10) <<" "<< "Do you wish to do another conversion? y for yes, n for no "; // rerun loop on y for yes
cin >> again;
}while (again == 'Y' || again =='y');
}
void c_to_f(void)
{
system("CLS"); // clear screen for function data.
int km,m;
cout << "\n\n\n";
cout << setw(10) <<" "<< "Enter your value \a";
cin >> km;
m = km * 1000;
cout << endl << setw(10) <<" "<< km << " km is " << m << " m \a\n\n\n";
}
void f_to_c(void)
{
system("CLS"); // clear screen for function data.
int km,m;
cout << "\n\n\n";
cout << setw(10) <<" "<< "enter the value \a";
cin >> m;
km = m / 1000;
cout << endl << setw(10) <<" "<< km << " m is " << km << " km \a\n\n\n";
}