Fill in the blank Question 1 (10 points) Question 1 options: Complete the follow
ID: 3558923 • Letter: F
Question
Fill in the blank
Question 1 (10 points)
Question 1 options:
Complete the following code.
This section of code will ask the user for a number, then store what was typed it into a variable calleddiceRoll.
int
__________
;
cout << 'Please enter a number:';
_____________ >> ____________
;
Save
Question 2 (10 points)
Question 2 options:
Complete the following code.
This section of code check if a variable called diceRoll isn't between 1 and 6 (an invalid dice rolls) and print a message when it isn't.
if ( (diceRoll
___________ 0) __________ (diceRoll ________ 7) ) // this line has extra parentheses in it for readability
{
cout << 'The number you entered isn't valid!';
exit(1); // quit the program with an error code of 1
}
Question 3 (10 points)
Question 3 options:
Complete the following code.
This section of code checks if a variable called diceRoll is equal to 1, then prints the message 'Body Added'
if (diceRoll
________________ 1)
{
cout << 'Body Added';
}
Question 4 (10 points)
Question 4 options:
Complete the following code.
This section of code checks if a variable called diceRoll is equal to 2, then prints the message 'Head Added'
if (diceRoll
__________ 2)
{
cout << 'Head Added';
}
Explanation / Answer
Question 1 options:
Complete the following code.
This section of code will ask the user for a number, then store what was typed it into a variable called diceRoll.
int diceRoll;
cout << 'Please enter a number:';
cin >> diceRoll;
Question 2 options:
Complete the following code.
This section of code check if a variable called diceRoll isn't between 1 and 6 (an invalid dice rolls) and print a message when it isn't.
if ( (diceRoll <= 0) || (diceRoll >= 7) ) // this line has extra parentheses in it for readability
// when diceRoll is less than zero or more than seven then it is invalid.
{
cout << 'The number you entered isn't valid!';
exit(1); // quit the program with an error code of 1
}
Question 3 options:
Complete the following code.
This section of code checks if a variable called diceRoll is equal to 1, then prints the message 'Body Added'
if (diceRoll == 1) // just put == sign
{
cout << 'Body Added';
}
Question 4 options:
Complete the following code.
This section of code checks if a variable called diceRoll is equal to 2, then prints the message 'Head Added'
if (diceRoll == 2) // just put == sign
{
cout << 'Head Added';
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.