My code is returning crazy numbers. I am not sure what I am doing wrong. I have
ID: 3551757 • Letter: M
Question
My code is returning crazy numbers. I am not sure what I am doing wrong. I have to use one function for input, at least one function for calculations and one function for output. I am also doing call by reference. I belive the only problem is in my calculations function bbut it may somewhere else. If some one could spot the problem and explain it to me I would appreciate it.Here is my code:
#include<iostream>
using namespace std;
void obtainValues(double& input1,double& input2);
//sets values for feet and inches
void usToMetric(double& feet,double& inches);
// coverts feet to meters and inches to centimeters
void convResults(double& output1,double& output2);
//shows the length in meters and centimeters
int main()
{
double var1,var2;
cout<<"Enter the length of an object in feet and inches. First enter amount of feet, and secondly enter the remaining amount of inches. ";
cin>>var1;
cin>>var2;
obtainValues(var1,var2);
usToMetric(var1,var2);
convResults(var1,var2);
return 0;
}
void obtainValues(double& input1,double& input2)
{
double feet,inches;
input1=feet;
input2=inches;
}
void usToMetric(double& feet,double& inches)
{
double m,cm;
m=feet*.3048;
cm=inches/2.54;
}
void convResults(double& m,double& cm)
{
cout<<"The length of your object is "<<m<<" meters and "<<cm<<" centimeters. ";
}
Explanation / Answer
#include<iostream>
using namespace std;
void obtainValues(double& input1,double& input2);
//sets values for feet and inches
void usToMetric(double& feet,double& inches);
// coverts feet to meters and inches to centimeters
void convResults(double& output1,double& output2);
//shows the length in meters and centimeters
int main()
{
double var1,var2;
obtainValues(var1,var2);
usToMetric(var1,var2);
convResults(var1,var2);
return 0;
}
void obtainValues(double& input1,double& input2)
{
cout<<"Enter the length of an object in feet and inches. First enter amount of feet, and secondly enter the remaining amount of inches. ";
cin>>input1;
cin>>input2;
}
void usToMetric(double& feet,double& inches)
{
feet=feet*.3048;
inches=inches/2.54;
}
void convResults(double& m,double& cm)
{
cout<<"The length of your object is "<<m<<" meters and "<<cm<<" centimeters. ";
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.