My question for this is how do I get the output to not have a number number for example:
Input first distance...
Meters: 3
Centimeters: 56
Millimeters: 2
Input second distance...
Meters: 5
Centimeters: 39
Millimeters: 6
The first distance is 3562 mm.
The second distance is 5396 mm.
The difference is 1834 mm.
This is my desired output but for some reason I keep on getting -1834 instead of 1834. If anyone can help me that would be great thanks!
#include <iostream>
using namespace std;
int NumMillimeters(int,int,int); //Function prototype
int main()
{
//variables
int meters; //to hold meters
int centimeters; //to hold centimeters
int millimeters; //to hold millimeters
int secondMeters; //to hold the second meter input
int secondCentimeters; //to hold the second centimeter input
int secondMillimeters; //to hold the second millimeter input
int firstDistance; //to hold the first distance in units of millimeters
int secondDistance; //to hold the second distance in units of millimeters
int difference; // the difference of the first and second difference
//ask the user for the meters, centimeters, and millimeters.
cout << "Input first distance...\n";
cout << "Meters: ";
cin >> meters;
cout << "Centimeters: ";
cin >> centimeters;
cout << "millimeters: ";
cin >> millimeters;
firstDistance = NumMillimeters(meters, centimeters, millimeters);
//Call to function NumMillimeters and put the value in firstDistance.
//ask the user for the second set of meters, centimeters, and millimeters.
cout << "\nInput second distance...\n";
cout << "Meters: ";
cin >> secondMeters;
secondDistance = NumMillimeters(secondMeters, secondCentimeters, secondMillimeters); //Call to function NumMillimeters and put value in secondDistance.
//Print the equivalent distance in millimeters of each distance.
cout << "\nThe first distance is " << firstDistance << " mm.\n";
cout << "The second distance is " << secondDistance << " mm.\n";
difference = (firstDistance - secondDistance); //Calculate the difference of the two distances.
cout << "The differenece is " << difference << " mm.\n"; //Print the difference of the two differences.
return 0;
}
int NumMillimeters(int meters, int centimeters, int millimeters)
{
int distance; //To hold the distance with in millimeters.
return distance = (meters * 1000) + (centimeters * 10) + millimeters;
//Calculate the conversion to millimeters and put it in distance.
Input first distance...
Meters: 1932
Centimeters: 45
millimeters: 67
Input second distance...
Meters: 1834
Centimeters: 78
millimeters: 12
The first distance is 1932517 mm.
The second distance is 1834792 mm.
The differenece is 97725 mm.
Process returned 0 (0x0) execution time : 21.074 s
Press any key to continue.
PS: though be aware that with ints you will not be able to handle decimal inputs