I created a dice program and below is my header file. You roll 2 dice and the value of the two dice are calculated. *Face is the number of sides of the dice, *value is the number on each side. My question is regarding the increment and decrement operator. Ive done the prefix and postfix increment by incrementing the *value by 1.
My question is how to proceed with the code for when the value reaches over *face, wrap back to 1? In other words when you increment the value 6 by 1, the total is 7, but as we know a die does not carry the value of 7, so we wrap it back to the value of 1.
#include <iostream>
int increment(int input){
if (input % 6 == 0 ) // if six divdes evenly into input
// set input to 6
input = 6;
else
input = input % 6; // else input = the remainder of input / divided by six
return input;
}
int main(){
// quick test on inputs 1-12
for (int i = 1; i < 13; i++) {
std::cout << increment(i) << std::endl;
}
return 0;
}
1
2
3
4
5
6
1
2
3
4
5
6
Program ended with exit code: 0