Need help hiding 0th Rolls on a DND "simulator."

Hey there!

I need help to understand why my code is giving me 0th and last "rolls."
If you run the code, enter your "prof bonus," and the number of attacks, it will give you the call outs I ask for, but an additional call out before and after the number of attacks indicating the roll was a "0."

This also affects my "total damage" call out. If I could get it to only call out the rolls and the total damage for the rolls asked for, that would be ideal.

Of course, if you're familiar with D&D, this is not how the game works, but for my purposes, I just need it to run "prettily" enough.

Any insight would be greatly appreciated!

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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  #include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

class Dice
{
public:
Dice();
void Roll();
void Display();
void Reset();

private:
int LastRoll;
int TotalAttacks;
int TotalDamage;
};

Dice::Dice() : LastRoll(0), TotalAttacks(0), TotalDamage(0)
{ }

double prof;
double attacks;

void Dice::Roll()
{
LastRoll = 0;
TotalAttacks ++;

// Generate a random number between 1 and 20

LastRoll = (rand() % 20) + 1;
TotalDamage += LastRoll;
}

void Dice::Display()
{
cout << "Your last roll was a " << LastRoll << ", and your attack roll is " << LastRoll + prof << "." << endl;
cout << "You have attacked " << TotalAttacks << " times." << endl;
cout << "Your total damage is " << TotalDamage + attacks*prof << "." << endl << endl;
}

void Dice::Reset()
{
LastRoll = 0;
TotalDamage = 0;
TotalAttacks = 0;
}

int main()
{

// Greeting header
cout << "Welcome to the DND Battle simulator!" << endl;
// Input proficiency bonus
cout << "Please input your adventurer's proficiency bonus " << endl;
cin >> prof;
// Enter number of attacks
cout << "And now, how many times are you attacking?" << endl;
cin >> attacks;

// seed the random number generator
srand(static_cast<unsigned int>(time(0)));

Dice MyDice;
MyDice.Display();

for (int i = 0; i < attacks; i++)
{
MyDice.Roll();
MyDice.Display();
}

MyDice.Reset();
MyDice.Display();

cin.get();
return 0;
}
You have a Display() call before and after your loop, as well as in the loop.
Oh my. I don't know how I missed that.

Thank you so much, dutch!
Topic archived. No new replies allowed.