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

Use C++ On a roulette wheel, the pockets are numbered 0 thru 36. The colors of t

ID: 3904293 • Letter: U

Question

Use C++

On a roulette wheel, the pockets are numbered 0 thru 36.   The colors of the pockets are as follows:

Pocket 0 is green

For Pockets 1 thru 10, the odd-numbered pockets are red and the even numbered pockets are black.

For Pockets 11 thru 18, the odd-numbered pockets are black and the even numbered pockets are red.

For Pockets 19 thru 28, the odd-numbered pockets are red and the even numbered pockets are black.

For Pockets 29 thru 36, the odd-numbered pockets are black and the even numbered pockets are red.

Create a C++ project which that asks the user to enter a pocket number and displays whether the pocket is green, red or black. The program should display an error message if the user enters a number that is outside the range of 0 through 36. Name your file roulette.cpp.

Hint: Keep in mind that a number can be identified as even/odd by examining the remainder of int division by2.

Hint:   Use the % operator to determine if a number is even or odd. If a number is divided by 2 it either has a remainder of 0 or 1. If the remainder is 0, the number is even. If the remainder is 1 if the number is odd.

Explanation / Answer

Given below is the code for the question.
Please do rate the answer if it was helpful. Thank you

#include <iostream>
#include <string>
using namespace std;
int main()
{
int num;
string color;

cout << "Enter a pocket number (0-36): ";
cin >> num;

if(num < 0 || num > 36)
{
cout << "Invalid pocket number!" << endl;
}
else
{
if(num == 0)
color = "green";
else if(num <= 10) // 1- 10
{
if(num % 2 == 0) // even
color = "black";
else
color = "red";
}
else if((num>= 1 && num <= 10) || (num>= 19 && num <= 28)) // 1 thru 10, 19 thru 28
{
if(num % 2 == 1) // odd
color = "red";
else
color = "black";
}
else if((num>= 11 && num <= 18) || (num>= 29 && num <= 36)) // 11- 18
{
if(num % 2 == 1) // odd
color = "black";
else
color = "red";
}


cout << "The color of pocket " << num << " is " << color << endl;
}
}


output
=====
Enter a pocket number (0-36): 15
The color of pocket 15 is black

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote