I am currently working on a dice rolling program for my CS121 class and this is my code. I am trying to write a function that rolls a 6 sided die and rerolls it when it rolls 1. I want to call that function 3 times and then add the outputs of the functions together. unfortunately underneath roll2 when I am trying to add it and output it there is a red line and when I hover over it it states "expression must have integral or unscoped enum type. I am stumped so if you could help me find a way around this that would be great.
#include <iostream>
using namespace std;
void diceroll() {
int result = ((rand() % 6) + 1);
if (result != 1)
cout << result << + " ";
else cout << result << +" ";
}
int main() {
auto roll1 = diceroll;
auto roll2 = diceroll;
auto roll3 = diceroll;
cout << "The total of the 3 numbers is" << endl;
cout << roll1 + roll2 + roll3;
}
Aucun commentaire:
Enregistrer un commentaire