Conversions/void functions

Hi, I am supposed to be converting numbers from cm to inches using void functions.
When I debug, I can enter the cm, but it is not converted correctly, which leads me to think that there is something wrong with my mathematical part. I know that 1 in = 2.54 cm, but I can not for the sake of me figure out what I am doing wrong, I have changed my code 1oo times, so its probably good and messed up now. could someone point me in the correct direction??


#include <iostream>
#include <iomanip>
using namespace std;

//function prototype
void calcInches(double cmMeasurement, double inMeasurement);


int main()
{
double centimeters = 0.0;
double inches = 0.0;

cout << "Enter Centimeter Measurement: ";
cin >> centimeters;
calcInches(centimeters, inches);

cout << fixed << setprecision(0);
cout << "Inches Measurement: " << inches << endl;
return 0;
} //end of main function

//*****function definitions*****
void calcInches(double cmMeasurement, double inMeasurement)
{
cmMeasurement = inMeasurement * 2.54;
} //end of calcInches function
Last edited on
Line 6, 24: Your second argument is passed by value which means calcInches() is working on a copy of the value. Any changes made to cmMeasurement are not reflected in the caller.

Change lines 6 and 24 to pass the second argument by reference.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
Thank you so much! this is my first time posting to the forum here.
Topic archived. No new replies allowed.