I searched for this for a while, and asked my professor, but neither of us are sure exactly what's going on. That likely means it's a typo somewhere, but every time I run this code, for whatever reason, it calls all functions regardless of whether the if statement evaluates to true
int main()
{
char StartUnit, EndUnit;
double StartVal = 0, EndVal = 0;
double CalcVal = 0;
static double result = 0;`
` //Receive user input`
` cout << "Please enter the unit which you would like to convert from: ";
cin >> StartUnit;
cout << "What is your initial value?: ";
cin >> StartVal;
cout << "Please enter the unit which you would like to convert to: ";
cin >> EndUnit;
`//Step 1: Convert input to celsius`
`if (StartUnit = 'f')
{
CalcVal = FarCel(StartVal);
}`
`if (StartUnit = 'k')
{
CalcVal = KelCel(StartVal);
}`
`if (StartUnit = 'r')
{
CalcVal = RakCel(StartVal);
}`
//Step 2: Conver celsius to desired value
cout << CalcVal;
return 0;
}
`
When I output CalcVal, no matter what, it seems to run through all three functions. It doesnt matter what I type, r, c, f, they all evaulate the same. Could I have some advice on where I'm going wrong?
The random quotes scattered were from before I read about CTRL+K
Aucun commentaire:
Enregistrer un commentaire