// CSE 9A Fall 1996 UCSD // Assignment 3 // This program converts mile to kilometers // and kilometers to miles. It will repeat // these claculations until the user quits the program. #include const double MPK = 0.62137; //miles per kilometer void new_line(); //Discards all the input remaining on the current input line. char from_miles_or_kilometers(); //Returns 'M' if the user wants to convert from miles to kilometers. //Returns 'K' if the user wants to convert from kilometers to miles. //Gets the answer by asking the user. //Keeps asking the user until it gets an appropriate answer. void miles2kilometers(int precision_number); //Carries on a dialogue with the user that //converts an amount of miles to an equivalent //amount of kilometers. The results are //displayed with precision_number digits //after the decimal point. void kilometers2miles(int precision_number); //Carries on a dialogue with the user that //converts an amount of kilometers to an equivalent //amount of miles. The results are //displayed with precision_number digits //after the decimal point. int main() { cout << "This program will let you convert from\n" << "miles to kilometers or\n" << "from kilometers to miles.\n" << endl << "You will be allowed to choose how many digits after\n" << "the decimal point that there will be in the answer.\n" << endl; int number_of_digits; char ans; do { YOU FILL IN THE CODE THAT GOES HERE. cout << "Do another calculation? (yes/no): "; cin >> ans; new_line(); //Discards the "es" in "yes" and the "o" in "no" } while ((ans == 'y') || (ans == 'Y')); return 0; } //You do not need to understand the following //function definition. You just have to use it. void new_line() { char symbol; do { cin.get(symbol); } while (symbol != '\n'); } YOU PUT THE REST OF THE FUNCTION DEFINITIONS HERE. THE FUNCTION from_miles_or_kilometers() MUST USE A LOCAL VARAIABLE NAMED ans THAT IS OF TYPE int.