可能重复:
如何让 C++ 求解输入值的方程?
我是 C++ 新手,只是在玩……
#include <iostream>
using namespace std;
int limbs(int handdmg, int armdmg, int chestdmg, int headshot, int legdmg)
{
return handdmg + armdmg + chestdmg + legdmg + headshot;
}
main ()
{
int totaldmg;
int handdmg;
int armdmg;
int chestdmg;
int legdmg;
int headshot;
int Dmgdial;
int x;
// limiting the variables to a smaller range of integers
handdmg = 0 < x < 5;
armdmg = 10 < x < 15;
chestdmg = 25 < x < 50;
legdmg = 30 < x < 40;
headshot = 80 < x < 120;
cout << "Enter your total damage taken:" << endl;
cin >> totaldmg;
Dmgdial = totaldmg;
// want the variables to = the input value in the best smallest way possible
limbs(handdmg, armdmg, chestdmg, headshot, legdmg) = Dmgdial;
// then print the variables answers to the screen
cout << "damage given to the hand: " << handdmg << endl;
cout << "damage given to the arm: " << armdmg << endl;
cout << "damage given to the chest: " << chestdmg << endl;
cout << "damage given to the leg: " << legdmg << endl;
cout << "damage given to the head: " << headshot << endl;
cin.clear();
cin.ignore(2505, '\n');
cin.get();
return 0;
}
所以这个概念很简单——你在程序中输入一个值,例如 156,然后让计算机使用 x 的有限值计算获得该值的最佳方法。
但是,limbs(handdmg, armdmg, chestdmg, headshot, legdmg) = Dmgdial
不起作用。就编译器而言,它是倒退的。
我怎样才能让这种类型的程序工作?