All- I've researched this quite a bit. My program compiles without error, but the values from the functions within the struct are not passing to the program. Can you help me to figure out why they are not? I included the snippets of code that show the components in question. Mainly, my code like: "&allData::ConvertToC" is not returning any value from the function within the struct "allData". It only will return a value of 1, no matter the input of "allData.temperature". I know the all components of the program, other than those mentioned are working.
code snippets:
//defining the struct
struct allData {
char selection;
double centigrade;
double fahrenheit;
double temperature;
double ConvertToC (const double& temperature);
double ConvertToF (const double& temperature);
} allData;
//adding data to the struct for the functions within the struct to use
cout << "Enter C for converting your temperature to Celsius, or enter F for converting your temperature to Fahrenheit, and press ENTER." << endl << endl;
cin >> allData.selection;
cout << "Enter your starting temperature to two decimal places, and press ENTER." << endl << endl;
cin >> allData.temperature;
switch (allData.selection) {
//my attempt to reference the functions within the struct and the data in the struct, but it is not working and always returns a value of 1.
case 'c': { &allData::ConvertToC;
cout << "Your temperature converted to Celsius is: " << &allData::ConvertToC
<< endl << endl;
break;
}
case 'C': { &allData::ConvertToC;
cout << "Your temperature converted to Celsius is: " << &allData::ConvertToC
<< endl << endl;
}
}
//Function definitions that are located in the struct. Do I define the functions in the normal way, like this, if they are located in the struct?
double allData::ConvertToF (const double& temperature) {
double fahrenheit = 0;
fahrenheit = temperature * 9 / 5 + 32;
return fahrenheit;
}
double allData::ConvertToC (const double& temperature) {
double centigrade = 0;
centigrade = (temperature - 32) * 5 /9;
return centigrade;
}
&allData::ConvertToCis the address of the method, your are not calling it, you need to doallData.ConvertToC(allData.temperature).