so i was bored and decided to make a dice simulator, and i ran into a error.
heres the code
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int total[12];
int dice1;
int dice2;
int aitotal[12];
int aidice1;
int aidice2;
void Roll(){
srand(time(0));
dice1 = 1+ (rand() %6);
dice2 = 1+ (rand() %6);
}
int DiceTotal(){
total[12] = dice1+dice2;
return total[12];}
void PrintDice(){
cout<<"Your dice numbers are: "<<dice1<<" and "<<dice2<<endl;
cout<<"Your dice total is: "<<total[12]<<endl<<endl;}
void AiRoll(){
srand(time(0));
aidice1 = 1+ (rand() %6);
aidice2 = 1+ (rand() %6);
cout<<"Ai's dices are "<<aidice1<<" and "<<aidice2<<endl<<endl;
}
int AiDiceTotal(){
aitotal[12] = aidice1+aidice2;
cout<<"Ai total is"<<aitotal[12]<<endl;
return aitotal[12];}
void Compare();
bool open= true;
int main()
{
do{
Roll();
DiceTotal();
cout<<"To start game, press 1"<<endl;
int go;
cin>>go;
if(go==1){
PrintDice();
AiRoll();
AiDiceTotal();
Compare();
}
else{cout<<"Wrong in put idiot!"<<endl;
}
}while(open==true);
}
void Compare(){if(DiceTotal>AiDiceTotal){
cout<<"You win!!"<<endl;}
else if(AiDiceTotal>DiceTotal)
{cout<<"You lose!!"<<endl;
}
else if(DiceTotal==AiDiceTotal){
cout<<"TIEE!!"<<endl;}
else{
cout<<"Errror"<<endl;}
}
i wanted the output to be
dice number 6, 2
dice total 8
instead i get
dice numbers 8 2
dice total 8
ai is fine.
btw sorry for sloppy coding and no comments i made it really quickly.