CPP Code on Target Practice

 TARGET PRACTICE

Drona normally trains his disciples using a board which consists of concentric circles. When a student correctly hits the center of the concentric circles, his score is 100. The score gets reduced depending on where the students hit on the board. When the student hits outside the board, his score is 0. Drona will not allow a student to have his food unless he scores 100. Arjuna will always hit the target in his first attempt and he will leave early. Others may take more turns to reach a score of 100. Now, write a program to determine the number of turns a disciple takes to reach the target score of 'n'.

INPUT FORMAT:
Input consists of a list of positive integers. 
The first integer corresponds to the target score 'n'. 
Assume that all the other integers input are less than or equal to n.
OUTPUT FORMAT:
The output consists of a single line. Refer the sample output for format details.
SAMPLE INPUT 1 :
100
4
40
60
SAMPLE OUTPUT 1 :
The number of turns is 3
SAMPLE INPUT 2 :
1000
1000
SAMPLE OUTPUT 1 :
The number of turns is 1

Logic to follow to get the Problem solve

1. Declare required variables.
2. Initialize the sum ans count variables to zero (i.e., sum=0, count=0).
3. Apply the required looping (do-while) in this case.
4. Increment the count and get the inputs under loop.
5. Sum the inputs that has been taken ( i.e., sum=sum+a )
6. Now until the sum is smaller than the target score(i.e., n) count the number of turns.
7. Finally print the count result outside the looping stamements.

Let's Write the Coding Part of the Problem 

Code : 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
#include<iostream>
using namespace std;
int main()
{
  int a, n, sum=0, count=0, i;
  cin>>n;
    do
    {
        count++;
        cin>>a;
        sum+=a;
        i++;
    }
    while(sum<n);
        printf("The number of turns is %d",count);
  return 0;
 }

Sample test cases passed Successfully

If you liked this post, then share this with your friends and if anything is confusing or incorrect then let me know in the comment section.

Thanks from my side, this is Mayank, keep learning and exploring !!

Next Post
No Comment
Add Comment
comment url