Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to have a C++ program solve for variables of an input value given the variables are limited integers?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/12120369/how-to-have-c-solve-the-equation-for-an-input-value">How to have C++ solve the equation for an input value?</a> </p> </blockquote> <p>I'm new to C++ and am just playing around... </p> <pre><code>#include &lt;iostream&gt; 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 &lt; x &lt; 5; armdmg = 10 &lt; x &lt; 15; chestdmg = 25 &lt; x &lt; 50; legdmg = 30 &lt; x &lt; 40; headshot = 80 &lt; x &lt; 120; cout &lt;&lt; "Enter your total damage taken:" &lt;&lt; endl; cin &gt;&gt; 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 &lt;&lt; "damage given to the hand: " &lt;&lt; handdmg &lt;&lt; endl; cout &lt;&lt; "damage given to the arm: " &lt;&lt; armdmg &lt;&lt; endl; cout &lt;&lt; "damage given to the chest: " &lt;&lt; chestdmg &lt;&lt; endl; cout &lt;&lt; "damage given to the leg: " &lt;&lt; legdmg &lt;&lt; endl; cout &lt;&lt; "damage given to the head: " &lt;&lt; headshot &lt;&lt; endl; cin.clear(); cin.ignore(2505, '\n'); cin.get(); return 0; } </code></pre> <p>So the concept is simple - you enter a value such as 156 into the program and then have the computer calculate the best way to get that value using the limited values of x. </p> <p>However, <code>limbs(handdmg, armdmg, chestdmg, headshot, legdmg) = Dmgdial</code> doesn't work. It's backwards as far as the compiler is concerned.</p> <p>How would I get this type of program to work? </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload