Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use C++ to match all tries thank you For given amount of gold that the user wish

ID: 3886827 • Letter: U

Question

Use C++ to match all tries thank you

For given amount of gold that the user wishes to spend, we can use a computer program to calculate the optima amount of health H and armor A that will maximize the Effective Heath E. The two formulae that we will use are E = H (100 + A)/100 GoldToSpend = 2 middot H + 18 middot A. Write a C program that asks the player how much gold they wish to spend, then calculates the optimal amount of H and A that the user should purchase in order to maximize E. Tips to solving this problem: Loop structure must be used, otherwise 0 point for this problem. 1. Loop across all possible values of A: The minimum amount of armor that can be purchased is A = 0 and the maximum amount is A = Goldrospend/18 2. For a given amount of A, solve the GoldToSpend equation for H 3. Calculate E. 4. Keep track of the maximum amount of E seen during the loop. Also keep track of the corresponding A and H used to calculate the maximum E. 5. Report the results. Sample Code Execution: Red text indicates information entered by the user How much gold do you wish to spend? 10 For 10 gold you should buy 5 Health, and 0 Armor for an effective health score of 5.000 Sample Code Execution: Red text indicates information entered by the user How much gold do you wish to spend? 1000 For 1000 gold you should buy 500 Health, and 0 Armor for an effective health score of 500.000 Sample Code Execution: Red text indicates information entered by the user How much gold do you wish to spend? 10000 For 10000 gold you should buy 2948 Health, and 228 Armor for an effective health score of 9669.440 Sample Code Execution: Red text indicates information entered by the user How much gold do you wish to spend? 1820 For 1820 gold you should buy 901 Health, and 1 Armor for an effective health score of 910.010 Sample Code Execution: Red text indicates information entered by the user How much gold do you wish to spend? 3603 For 3602 gold you should buy 1351 Health, and 50 Armor for an effective health score of 2026.500

Explanation / Answer

#include<stdio.h>
#include<iostream>
using namespace std;

int main()
{

int goldSpend;
float h,e,max_E=0,final_H,final_A;
// User input
cout << "How much gold do you wish to spend ? : ";
cin >> goldSpend;

// Loop for the all possible Armor
for (int a =0; a <=(goldSpend/18) ; a++)
{
        // Calculate Health for the current Armor
        h = (goldSpend - (18*a))/2;
        // Calculate Effective Health
        e = (h*(100+a))/100;
        // Find the Max Effective health
        if(max_E < e)
        {
                final_A = a;
                final_H = h;
                max_E = e;
        }
}
// Output
cout << "For " << goldSpend << "glod you should buy " << final_H << " Health, and " << final_A << " Armor for an effective health score of " << max_E << endl;

return(0);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote