D
DrNoose
Hi!
I'm just getting started learning c++. I have a program that is driving
me nuts! I think I have it working all but one portion. Basically, you
input a number of "meters" as a double. The program is supposed to
convert the meters into feet & inches. I understand that to get the feet
part - meters (in this case meters is a pass by reference) is to be
multiplied by 3.2808. I know I should have something like feet = ***,
but I get an error because I'm mixing int's with doubles?
Here is my program so far. It should have the following input/output:
"Enter a number of meters as a double"
5.00
The value of 5.00 meters and centimeters converted to English measure is
16 feet, 4.85 inches.
"Y or y continues, any other character quits." (if you choose "other
charc." then it says "Goodbye!"
I think my problem is in the void convert function.
This is the output that I usually get:
"The value of meters, centimeters 5.00 converted to English measure is
-4194884 feet, 1.37 inches.
Y or y to continues, any other character quits
Any help is greatly appreciated!
Thanks!
Kathy
//********************************************************************************************
//
// Meters&CentemetersToFeet&Inches.cpp
//
// This program prompts the user for a length separated into the meters
and centimeters,
// converts the length into feet and inces and displays the converted length
// to the user. The user is given the opportunity to repeat the conversion.
//
//
//********************************************************************************************
#include <iostream>
#include <iomanip>
using namespace std;
void input(double& meters);
void convert(int& feet, double& inches, double meters);
void output(int feet, double inches, double meters);
int main()
{
int feet;
double inches, meters;
char ans;
do
{
input(meters);
convert(feet, inches, meters);
output(feet, inches, meters);
cout << "Y or y continues, any other character quits "
<< endl;
cin >> ans;
} while('Y' == ans || 'y' == ans);
cout << endl;
cout << "Goodbye!\n";
return 0;
}
void input(double& meters)
{
cout << "Enter a number of meters as a double \n";
cin >> meters;
}
void convert(int &feet, double& inches, double meters)
{
inches = (meters * 3.2808) / 12;
}
void output(int feet, double inches, double meters)
{
cout << fixed << showpoint;
cout << setprecision(2);
cout <<"The value of meters, centimeters " << meters << endl;
cout << " converted to English measure is " << feet << " feet, "
<< inches << " inches" << endl;
}
I'm just getting started learning c++. I have a program that is driving
me nuts! I think I have it working all but one portion. Basically, you
input a number of "meters" as a double. The program is supposed to
convert the meters into feet & inches. I understand that to get the feet
part - meters (in this case meters is a pass by reference) is to be
multiplied by 3.2808. I know I should have something like feet = ***,
but I get an error because I'm mixing int's with doubles?
Here is my program so far. It should have the following input/output:
"Enter a number of meters as a double"
5.00
The value of 5.00 meters and centimeters converted to English measure is
16 feet, 4.85 inches.
"Y or y continues, any other character quits." (if you choose "other
charc." then it says "Goodbye!"
I think my problem is in the void convert function.
This is the output that I usually get:
"The value of meters, centimeters 5.00 converted to English measure is
-4194884 feet, 1.37 inches.
Y or y to continues, any other character quits
Any help is greatly appreciated!
Thanks!
Kathy
//********************************************************************************************
//
// Meters&CentemetersToFeet&Inches.cpp
//
// This program prompts the user for a length separated into the meters
and centimeters,
// converts the length into feet and inces and displays the converted length
// to the user. The user is given the opportunity to repeat the conversion.
//
//
//********************************************************************************************
#include <iostream>
#include <iomanip>
using namespace std;
void input(double& meters);
void convert(int& feet, double& inches, double meters);
void output(int feet, double inches, double meters);
int main()
{
int feet;
double inches, meters;
char ans;
do
{
input(meters);
convert(feet, inches, meters);
output(feet, inches, meters);
cout << "Y or y continues, any other character quits "
<< endl;
cin >> ans;
} while('Y' == ans || 'y' == ans);
cout << endl;
cout << "Goodbye!\n";
return 0;
}
void input(double& meters)
{
cout << "Enter a number of meters as a double \n";
cin >> meters;
}
void convert(int &feet, double& inches, double meters)
{
inches = (meters * 3.2808) / 12;
}
void output(int feet, double inches, double meters)
{
cout << fixed << showpoint;
cout << setprecision(2);
cout <<"The value of meters, centimeters " << meters << endl;
cout << " converted to English measure is " << feet << " feet, "
<< inches << " inches" << endl;
}