减法给了我积极的结果 C++
Subtraction is giving me positive result C++
if (GoalWeight < 0.0) {
int weeks;
cout << "How many weeks do you plan to continue this trend?\n";
cin >> weeks;
double NewWeight = GoalWeight * weeks;
double NegBMI = (weight - NewWeight) * 703 / (pow(HeightConverter, 2));
cout << "If you complete your plan for " << weeks << "weeks you will have a new BMI of: \n" << NegBMI;
}
system("pause");
return 0;
}
输出结果:
What is your current weight?: 180
What is your current height in inches?" 71
Your current BMI is: 25.10(Not part of output, but this is correct)
What is your goal weight change?(lbs) -1.5
How many weeks do you plan to continue this trend?: 6
If you complete your plan for 6 weeks you will have a new BMI of: 26.36
你可以看出这是错误的
BMI 的计算方法是(体重 * 703)/身高^2(英寸)
它对负数的作用是:
180 + 9(instead of 180 - 9) giving (191 * 703) / 71^2 yielding 26.36
而不是:
180 - 9(giving 171 * 703) / 71^2 yielding the correct output of:23.84
我知道你们都在摇头说我一定是个白痴,这是理所当然的,我希望有人能帮助我!
What is your goal weight change?(lbs) -1.5
How many weeks do you plan to continue this trend?: 6
6 * ( -1.5 ) == -9
180 - (-9) == 189
因此,您要么将目标体重变化输入为正数,要么将其相加,而不是相减。
由于你的语句 6 * -1.5
,你的 newWeight
结果为 -9。如果你想减去它,只需制作 (weight + newWeight)
而不是 -
。
您是否相信如果您这样做 (+NewWeight)
NewWeight
的值变为正值?
事实并非如此:
一元加运算符(+):对数字类型的运算结果是操作数本身的值。此运算符已为所有数字类型预定义。
作为解决方案,使用 Reginalds 的想法并制作 (weight + newWeight)
而不是 -
。
if (GoalWeight < 0.0) {
int weeks;
cout << "How many weeks do you plan to continue this trend?\n";
cin >> weeks;
double NewWeight = GoalWeight * weeks;
double NegBMI = (weight - NewWeight) * 703 / (pow(HeightConverter, 2));
cout << "If you complete your plan for " << weeks << "weeks you will have a new BMI of: \n" << NegBMI;
}
system("pause");
return 0;
}
输出结果:
What is your current weight?: 180
What is your current height in inches?" 71
Your current BMI is: 25.10(Not part of output, but this is correct)
What is your goal weight change?(lbs) -1.5
How many weeks do you plan to continue this trend?: 6
If you complete your plan for 6 weeks you will have a new BMI of: 26.36
你可以看出这是错误的
BMI 的计算方法是(体重 * 703)/身高^2(英寸)
它对负数的作用是:
180 + 9(instead of 180 - 9) giving (191 * 703) / 71^2 yielding 26.36
而不是:
180 - 9(giving 171 * 703) / 71^2 yielding the correct output of:23.84
我知道你们都在摇头说我一定是个白痴,这是理所当然的,我希望有人能帮助我!
What is your goal weight change?(lbs) -1.5
How many weeks do you plan to continue this trend?: 6
6 * ( -1.5 ) == -9
180 - (-9) == 189
因此,您要么将目标体重变化输入为正数,要么将其相加,而不是相减。
由于你的语句 6 * -1.5
,你的 newWeight
结果为 -9。如果你想减去它,只需制作 (weight + newWeight)
而不是 -
。
您是否相信如果您这样做 (+NewWeight)
NewWeight
的值变为正值?
事实并非如此:
一元加运算符(+):对数字类型的运算结果是操作数本身的值。此运算符已为所有数字类型预定义。
作为解决方案,使用 Reginalds 的想法并制作 (weight + newWeight)
而不是 -
。