Can someone help run this and fix a small error I have when I run this. I get a
ID: 3872273 • Letter: C
Question
Can someone help run this and fix a small error I have when I run this. I get a constant variable error on line 62. I have a constant variable though and I'm sure what to change. I use Visual Basic 2017 as well for any of those wondering.
Please help and thanks in advance
#include <ctime>
#include <iostream>
#include <random>
#include <string>
using namespace std;
int main()
{
const int paper = 0, rock = 1, scissors = 2;
const string explanationPR = " wins because paper covers rock";
const string explanationRS = " wins because rock breaks scissors";
const string explanationSP = " wins because scissors cut paper";
// default_random_engine e(static_cast(time(nullptr)));
default_random_engine e;
uniform_int_distribution u(paper, scissors);
top:
int choiceA = u(e), choiceB = u(e);
const string nameA = "Ala", nameB = "Bel";
cout << nameA << " chooses ";
switch(choiceA){
case paper: cout << "paper";
break;
case rock:cout << "rock";
break;
case scissors: cout << "scissors";
break;
}
cout << endl;
cout << nameB << " chooses ";
switch(choiceB){
case paper: cout << "paper";
break;
case rock:cout << "rock";
break;
case scissors: cout << "scissors";
break;
}
cout << endl;
switch(choiceA) {
case paper: switch(choiceB){
case rock: cout << nameA << explanationPR << endl;
case scissors: cout << nameB << explanationSP << endl;
break;
}
case rock: switch(choiceB){
case paper: cout << nameB << explanationSP << endl;
case scissors: cout << nameA << explanationRS << endl;
break;
}
case scissors: switch(choiceB){
case paper: cout << nameA << explanationSP << endl;
case rock: cout << nameB << explanationRS << endl;
break;
}
case choiceB:
cout << "Tie game";
default:
cout << "something is wrong";
cout << endl;
break;
}
system("pause");
return 0;
}
Explanation / Answer
It was really confusing took me 2 hours but, with hit and trial I found out that In the 10th line from end on the program.
case choiceB:
cout << "Tie game";
is causing the error.
Also your way of choosing the Values is little confusing.
Corrected code: