Question

You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice verNow, modify the program from Part D to make sure that if user enters invalid input, the program shows an error message and as

Use functions to complete this C + + program

You want to write a converter program which will let user convert distance and weight from SI to the USCS system and vice versa The formulae are as follows: 1. Distance in miles- distance in kilometers x 1.60 2. Weight in kilograms weight in pounds x 2.20 The program would let user input the number that they want to convert and then choose the units to and from which they want to convert. The program should run as long as the user wants to keep on converting.
Now, modify the program from Part D to make sure that if user enters invalid input, the program shows an error message and asks for the user to correct input
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
#include <stdio.h>

using namespace std;
int main ()
{
double weight, distance;
int option, error;
cout << "Enter Weight and Distance \t";
//Input validation
do
{
error = 0;
cin >> weight >> distance;
if (cin.fail ())
   {
   cout << "Please enter a valid value" << endl;
   error = 1;
   cin.clear ();
   cin.ignore (80, '\n');
   }
}
while (error == 1);

//Conversion code
do
{
cout <<
   "select option to convert 1 for SI t0 USCS 2 for UCSC to SI and 0 to quit \n";
cin >> option;
if (option == 1)
   {
   distance = distance / 1.6;
   weight = weight * 2.2;
   cout << "converted weight and distance : weight = " << weight <<
   "pounds" << "\t distance = " << distance << "miles" << "\n";
   }
else if (option == 2)
   {
   distance = distance * 1.6;
   weight = weight / 2.2;
   cout << "converted weight and distance : weight = " << weight <<
   "kilograms" << "\t distance = " << distance << "kilometerss" <<
   "\n";

   }

} while (option != 0);

return 0;
}

Add a comment
Know the answer?
Add Answer to:
You want to write a converter program which will let user convert distance and weight from SI to ...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program that will convert miles to kilometers and kilometers to miles. The user will...

    Write a program that will convert miles to kilometers and kilometers to miles. The user will indicate both a number (representing a distance) and a choice of whether that number is in miles to be converted to kilometers or kilometers to be converted to miles Each conversion is done with a value returning function You may use the following conversions. 1 kilometer = .621 miles 1 mile = 1.61 kilometers Sample Run: Please input Convert miles to kilometers Convert kilometers...

  • Create the Code using C Program: 2. Write a program to convert the time from 24-hour...

    Create the Code using C Program: 2. Write a program to convert the time from 24-hour notation to 12-hour notation and vice-versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following function: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the...

  • C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have...

    C# Temp. Converter program. Create a Celsius and Fahrenheit Temperature Converter application. The application must have 2 Labels (each one of them assigned only to Celsius and Fahrenheit), 2 TextBoxes (each one of them assigned only to Celsius and Fahrenheit), only 1 Convert Button, 1 Clear Button, and 1 Exit Button. Also, 1 Error message label which will display the error messages. The application should only allow the user to enter the desired temperature just in one of the TextBoxes...

  • 1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice...

    1 Write a program to convert the time from 24-hour notation to 12-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore, your program must contain at least the following functions: a function to convert the time from 24-hour notation to 12-hour notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the...

  • Project 1, Program Design 1. Write a C program replace.c that asks the user to enter...

    Project 1, Program Design 1. Write a C program replace.c that asks the user to enter a three-digit integer and then replace each digit by the sum of that digit plus 6 modulus 10. If the integer entered is less than 100 or greater than 999, output an error message and abort the program. A sample input/output: Enter a three-digit number: 928 Output: 584 2. Write a C program convert.c that displays menus for converting length and calculates the result....

  • Write a Python program that does the following: Obtains the following input from a user: Mileage...

    Write a Python program that does the following: Obtains the following input from a user: Mileage at beginning of measurement period Mileage at end of measurement period Gallons of fuel consumed Calculates and displays: Miles driven Miles per gallon Kilometers driven Liters of fuel consumed Kilometers per liter Also incorporate some selection structure logic into it. If a vehicle gets less than 15 miles per gallon, display the message:       "Your vehicle has criminally low fuel efficiency." If it gets...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • Write a program that reads a string from the keyboard and tests whether it contains a...

    Write a program that reads a string from the keyboard and tests whether it contains a valid time. Display the time as described below if it is valid, otherwise display a message as described below. The input date should have the format hh:mm:ss (where hh = hour, mm = minutes and ss = seconds in a 24 hour clock, for example 23:47:55). Here are the input errors (exceptions) that your program should detect and deal with: Receive the input from...

  • Write a Python program that does the following: Obtains the following input from a user: Mileage...

    Write a Python program that does the following: Obtains the following input from a user: Mileage at beginning of measurement period Mileage at end of measurement period Gallons of fuel consumed Calculates and displays: Miles driven Miles per gallon Kilometers driven Liters of fuel consumed Kilometers per liter Incorporate some Selection structure logic into it: If a vehicle gets less than 15 miles per gallon, display the message:       "Your vehicle has criminally low fuel efficiency." If it gets 15...

  • Python Please. a)Let a program store the result of applying the eval function to the first...

    Python Please. a)Let a program store the result of applying the eval function to the first command-line argument. Print out the resulting object and its type. Run the program with different input: an integer, a real number, a list, and a tuple. (On Unix systems you need to surround the tuple expressions in quotes on the command line to avoid error message from the Unix shell.) Try the string "this is a string" as a commandline argument. Why does this...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT