Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this code completed, but am having issues running it every time. I am req

ID: 3598842 • Letter: I

Question

I have this code completed, but am having issues running it every time. I am requesting that // is used to explain the steps please as I just need help understanding my error, as I need to understand this in depth for my future career. Thank you for your time.

Card Monty. At the heart of the trick is this: there are three cards, one of which is a Queen of Hearts. The magician shuffles the cards, trying to deceive the participant, after which the participant must choose which card is the Queen of Hearts. If the participant chooses correctly, he/she wins. If not, the magician wins and takes the money and runs. Your program will emulate this trick. The program should offer the user the opportunity to see the rules for the game BEFORE the game is played. How this is implemented is up to you. The game play commences: The computer "shuffles" the cards by choosing a random number to represent the card that has the Queen of Hearts. The computer then asks the user to choose a card. If the user chooses the number of the correct card (e.g. the one that the computer chose as being the Queen of Hearts) he/she wins. If not the computer wins. Remember, you'll need to do some error checking. When you ask the user to enter a choice of a card (1, 2, or 3), the user might enter another number. You'll need to tell them that their choice was wrong and ask them to re-enter. Keep doing this until they enter a correct card number. Then the game proceeds. What's required to get full credit: First and foremost, the program has to work for all cases. The program must follow the formatting conventions we use in class. (Indentation, spacing, etc.) . . The program must be commented. You should include comments that have your name, the assignment, as well as comments for any areas of the program that should be explained. See the example we did in class for more information

Explanation / Answer

#include<iostream>
#include<stdlib.h>
#include<time.h>

using namespace std;

int main(){

    srand(time(NULL));
    int n;

    int pos = rand()%52 + 1; //There are total 52 cards so in a deck say the Queen's heart is at pos index in the deck of cards.
    cout << "=============Welcome to Card Monty============== ";
    cout << "The rule is you have to guess the position of Queen of Hearts after the counputer shuffles it ";
    cout << "If your guess is correct you win otherwise you loose ";
    while (1){
        cout << "Enter the position of Queen of hearts : ";
        cin >> n;
        if (n>= 1 && n<=52)
           break;
        else {
           cout << "Invalid value! (valid range 1-52) ";
        }
    }  
    if (n==pos)
       cout << "You win ";
    else {
        cout << "I am sorry you loose. The correct position is " << pos << endl;
    }
}