In the below code, it works fine except if u enter "e" or some letter when it asks for the number of dice to roll, it spams u with
Enter help for assistance:
Enter a command:
Enter help for assistance:
Enter a command:
Enter help for assistance:
and whenever its done rolling dice it does this
Enter a command:
Enter help for assistance:
Enter a command: _
?
Code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
int commandmain();
void funcroll6(void)
{
int roll6=0, num6roll=0, temproll;
cout<<"\n\nEnter a number of 6-sided dice to roll:";
cin>>num6roll;
while (num6roll>0)
{
temproll=(rand() % 6+1);
roll6=temproll+roll6;
num6roll = num6roll - 1;
}
if (roll6!=0)
cout<<"\n\nYou rolled for a total of "<<(roll6)<<"!";
else
cout<<"Be sure to enter a number of dice...";
}
int main()
{
time_t seconds;
time(&seconds);
srand((unsigned int) seconds);
while (commandmain()==0)
commandmain();
return 0;
}
int commandmain()
{
char command[256];
int commain=0;
cout<<"\n\nEnter a command:";
cin.getline(command, 256, '\n');
if(!strcmpi("dice", command))
{
funcroll6();
}
else if(!strcmpi("roll dice", command))
{
funcroll6();
}
else if(!strcmpi("roll them bones", command))
{
funcroll6();
}
else if(!strcmpi("help", command))
{
cout<<"\nSince this is a dice program, try:\n1.roll dice\n2.dice\n3.roll them bones\n4.quit";
}
else if(!strcmpi("quit", command))
{
commain=-1;
}
else
{
cout<<"\nEnter help for assistance:";
commain=0;
}
return (commain);
}