I have finished my program to convert feet and inches to centimeters, but i need to insert a loop that will ask the user if they want to run the program again. Where can I insert it? Also can someone explain the last line of my second function, all i know is that it works, but i dont know why. Thank you.
#include <iostream>
using namespace std;
void get_feet_inch(int& feet, int& inches);
void convert_to_meters(int feet, int inches, int& meters, int& centimeters);
void show_results(int feet, int inches, int meters, int& centimeters);
int main()
{
int feet;
int inches;
int meters;
int centimeters;
int main()
{
int feet;
int inches;
int meters;
int centimeters;
char letter;
do
{
get_feet_inch( feet, inches);
convert_to_meters(feet, inches, meters, centimeters);
show_results( feet, inches, meters, centimeters);
cout << "Would You like to perform task again: ";
cin >> letter;
}
while ( letter == 'y' || letter == 'Y');
return 0;
}
Adding a do while loop will make sure that it runs once and then it will ask the user if they want to do it again. If so, they enter y or Y and it will re run as long as the letter continues to be y or Y.
meters is an int variable, so the first line will assign the value stored in meters_double, rounded down to the nearest integer (ie truncate the decimals). So meters_double >= meters.