Question

Can someone help run this and fix a small error I have when I run this....

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;
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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:

#include <ctime>
#include <iostream>
#include <random>
#include <string>
#include <chrono>
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";


    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    default_random_engine e (seed);

    uniform_int_distribution<int> u(0, 2);
    
    int npc_choices[] = {paper, scissors, rock};
    
    int choiceA = npc_choices[u(e)];
    int choiceB = npc_choices[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;
    cout << "\n";
    
    switch (choiceA) {
    case paper:
        switch (choiceB) {
        case rock:
            cout << nameA << explanationPR << endl;
            break;
        case scissors:
            cout << nameB << explanationSP << endl;
            break;
          case paper: {
            cout << "Tie";
            break;
          }
        }
        break;
    case rock:
        switch (choiceB) {
        case paper:
            cout << nameB << explanationSP << endl;
            break;
        case scissors:
            cout << nameA << explanationRS << endl;
            break;
          case rock: {
            cout << "Tie";
            break;
        }
        }
        break;
      case scissors:
        switch (choiceB) {
          case paper:
            cout << nameA << explanationSP << endl;
            break;
          case rock:
            cout << nameB << explanationRS << endl;
            break;
          case scissors: {
            cout << "Tie";
            break;
        }
        }
        break;
    default:
        cout << "something is wrong";
        cout << endl;
        break;
    }
    
    return 0;
}
Add a comment
Know the answer?
Add Answer to:
Can someone help run this and fix a small error I have when I run this....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use Dev C++ for program and include all of the following. Im lost. Make sure the...

    Use Dev C++ for program and include all of the following. Im lost. Make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch. Make sure the user knows why he/she has won or lost – print a message like “Paper covers Rock” or “Scissors cuts Paper”. Ask the user how many times he/she wants to...

  • How to call a function in another function?C++ Project assistance. In the Project I am attempting...

    How to call a function in another function?C++ Project assistance. In the Project I am attempting to pass getOutcome into runGame to attempt to figure out who would win. Upon trying I get an error that getOutcome isn't in scop of runGame. The & symbols were my last attempt at trying to pass it, I do see it is wrong, and any help that can help me with just that is very appreciated. #include <iostream> #include <fstream> #include <string> #include...

  • Create the second part of a Rock, Paper, Scissors game. The game keeps playing as long...

    Create the second part of a Rock, Paper, Scissors game. The game keeps playing as long as the user enters 'Y'. Make this case sensitive; if they enter a lower case y the game will not continue. If the user enters in anything besides upper case Y the game will end. Your text must exactly match the examples below: Example 1 with correct input Let's play Rock, Paper, Scissors Enter 1 for rock, 2 for paper, 3 for scissors 2...

  • This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the...

    This is for C++ #include <random> #include <iostream> #include <ctime> using namespace std; /* In the game of craps, a shooter rolls 2 dice and adds the dots on the upper most faces of the dice. 7 or 11 on the first roll wins, 2, 3, or 12 on the first roll loses, andthing else is call the point and the player rolls again The following program fragment uses 1-way if statements simulate the 1st roll of the dice. Replace...

  • This is a C++ question need to complete project 2. attached the completed simple version of...

    This is a C++ question need to complete project 2. attached the completed simple version of the program below but need the updated version which is listed in the project 2 outline Project 2 Rock, Paper, Scissors Updated Take the solution to Lab 3 and make sure the user enters a letter of R, P, or S and the computer generates a number between 0-2 and changes that number to a letter of R, P or S, using a switch....

  • Hi there! I need to fix the errors that this code is giving me and also...

    Hi there! I need to fix the errors that this code is giving me and also I neet to make it look better. thank you! #include <iostream> #include <windows.h> #include <ctime> #include <cstdio> #include <fstream> // file stream #include <string> #include <cstring> using namespace std; const int N=10000; int *freq =new int [N]; int *duration=new int [N]; char const*filename="filename.txt"; int songLength(140); char MENU(); // SHOWS USER CHOICE void execute(const char command); void About(); void Save( int freq[],int duration[],int songLength); void...

  • Hello, I have some errors in my C++ code when I try to debug it. I...

    Hello, I have some errors in my C++ code when I try to debug it. I tried to follow the requirements stated below: Code: // Linked.h #ifndef INTLINKEDQUEUE #define INTLINKEDQUEUE #include <iostream> usingnamespace std; class IntLinkedQueue { private: struct Node { int data; Node *next; }; Node *front; // -> first item Node *rear; // -> last item Node *p; // traversal position Node *pp ; // previous position int size; // number of elements in the queue public: IntLinkedQueue();...

  • For C++ /* rewrite the following program to generate pairs of random number until the sum...

    For C++ /* rewrite the following program to generate pairs of random number until the sum of the digits of one random number equals the sum of the digits of the other random number. use only while loops in your solution. use only loop conditions to end the loop or escape the body of the loop. for example, 23( 5) 71( 8) 92(11) 6( 6) 13( 4) 99(18) 12( 3) 47(11) 63( 9) 18( 9) */ #include <cmath> #include <ctime>...

  • Please help fix my code C++, I get 2 errors when running. The code should be...

    Please help fix my code C++, I get 2 errors when running. The code should be able to open this file: labdata.txt Pallet PAG PAG45982IB 737 4978 OAK Container AYF AYF23409AA 737 2209 LAS Container AAA AAA89023DL 737 5932 DFW Here is my code: #include <iostream> #include <string> #include <fstream> #include <vector> #include <cstdlib> #include <iomanip> using namespace std; const int MAXLOAD737 = 46000; const int MAXLOAD767 = 116000; class Cargo { protected: string uldtype; string abbreviation; string uldid; int...

  • my code deosn't run and it doesn't show any error. what's wrong about it !! it...

    my code deosn't run and it doesn't show any error. what's wrong about it !! it should loads data from a text file into an array of structs and prints the array to the screen here is the code: #include <iostream> #include <string> #include <fstream> using namespace std; struct Company {    string Departmentname;    int Departmentnum; }; const int MAX = 20; int main() { ifstream File;    Company arrayofdepartment[MAX];    int Departmentcount ;      File.open("comapny.txt");       if...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT