- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures

- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces

# C++ code to count number of dice rolls to get target x

Suppose we have a number x. We have a six-faced dice and its faces are numbered from 2 to 7. We want exactly x points from the dice. When we throw the dice the face number will be added up to reach our target. We do not really care about the number of dice rolls, so we just want to know any number of rolls we can make to be able to get exactly x points for them. We are very lucky, so if the probability to get x points with chosen number of rolls is non-zero, we will be able to roll the dice in such a way. We have to find the number.

So, if the input is like x = 100, then the output will be 27, because we get 2, 11 times, 3, six times and 6, 10 times. (Other answers are also possible)

## Steps

To solve this, we will follow these steps −

return floor of (x / 2)

## Example

Let us see the following implementation to get better understanding −

#include<bits/stdc++.h> using namespace std; int solve(int x){ return x/2; } int main(){ int x = 100; cout << solve(x) << endl; }

## Input

100

## Output

50

- Related Articles
- Number of Dice Rolls With Target Sum in Python
- C++ code to count number of unread chapters
- C++ code to count number of weight splits of a number n
- C++ code to count number of notebooks to make n origamis
- C++ code to count number of packs of sheets to be bought
- Program to count minimum number of operations to flip columns to make target in Python
- C++ code to count number of even substrings of numeric string
- C++ code to count number of operations to make two arrays same
- C++ code to count number of times stones can be given
- C++ code to count number of lucky numbers with k digits
- Program to find number of ways we can arrange symbols to get target in Python?
- C++ code to count children who will get ball after each throw
- Program to count maximum number of distinct pairs whose differences are larger than target in Python
- C++ code to check grasshopper can reach target or not
- C++ code to count volume of given text