Mwahahahaha

(This problem was partly made by someone else.)

In C++, what will the program print? Sum all the printed fractions, then add the numerator and denominator of the resulting (simplified) fraction, then square the sum.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <string>

using namespace std;

struct character
{
    string name;
    int hitPoints;
    int maxHitPoints;
};

void harmCharacter(character characterToHarm, int health)
{
    characterToHarm.hitPoints -= health;

    if(characterToHarm.hitPoints < 0)
    {
        characterToHarm.hitPoints = 0;
    }
}    

void healCharacter(character characterToHeal, int health)
{
    characterToHeal.hitPoints += health;

    if(characterToHeal.hitPoints > characterToHeal.maxHitPoints)
    {
        characterToHeal.hitPoints = characterToHeal.maxHitPoints;
    }
}

int main()
{
    character player = {"Col. Mustard", 10, 15};

    cout << player.hitPoints << "/" << player.maxHitPoints << endl;

    harmCharacter(player, 7);

    cout << player.hitPoints << "/" << player.maxHitPoints << endl;

    healCharacter(player, 16);

    cout << player.hitPoints << "/" << player.maxHitPoints << endl;

    harmCharacter(player, 4);

    cout << player.hitPoints << "/" << player.maxHitPoints << endl;

    healCharacter(player, 1);

    cout << player.hitPoints << "/" << player.maxHitPoints << endl;

    cout << "Col. Mustard SUCKS!!! Professor Plum and Miss Scarlet are SO MUCH BETTER!!!!!" << endl;

    cout << endl;
    cout << endl;

    return 0;
} 
×

Problem Loading...

Note Loading...

Set Loading...