- 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++ Program to find out if a person has won lottery

Suppose, there is a jackpot lottery going on where there are 100 tickets, each ticket numbered within a number from 1 to 100. Now, the lottery company has decided only the player with ticket number 20 will win the jackpot prize, and ticket holders of number 11 to 21 will win a consolation prize each. So, we have to design the software for that. Given the ticket number, we have to print any one of these three messages, "Sorry, you have lost.", "You have won the jackpot!!!", and "You have won the consolation prize." The ticket number is supplied by the player, we have to print the message based on the ticket number.

## Problem Category

Various problems in programming can be solved through different techniques. To solve a problem, we have to devise an algorithm first, and to do that we have to study the particular problem in detail. A recursive approach can be used if there is a recurring appearance of the same problem over and over again; alternatively, we can use iterative structures also. Control statements such as if-else and switch cases can be used to control the flow of logic in the program. Efficient usage of variables and data structures provides an easier solution and a lightweight, low-memory-requiring program. We have to look at the existing programming techniques, such as Divide-and-conquer, Greedy Programming, Dynamic Programming, and find out if they can be used. This problem can be solved by some basic logic or a brute-force approach. Follow the following contents to understand the approach better.

So, if the input of our problem is like n = 12, then the output will be You have won the consolation prize.

## Steps

To solve this, we will follow these steps −

if n <= 10 or n >= 22, then: print("Sorry, you have lost.") Otherwise if n is same as 20, then: print("You have won the jackpot!!!") Otherwise, print("You have won the consolation prize.")

## Example

Let us see the following implementation to get better understanding −

#include<bits/stdc++.h> using namespace std; void solve(int n) { if(n <= 10 || n >= 22) cout<<"Sorry, you have lost."; else{ if(n == 20) cout<<"You have won the jackpot!!!"; else cout<<"You have won the consolation prize."; } } int main() { int n = 12; solve(n); return 0; }

## Input

12

## Output

You have won the consolation prize.

- Related Articles
- C++ code to find out who won an n-round game
- Program to find out if a vertex in an undirected graph has a lesser cost path in Python
- C++ Program to find out the number of sides that a polygon has inside a grid
- Program to find out if we win in a game in Python
- C++ Program to find out if there is a pattern in a grid
- Is Sex Safe If One Person Has Hepatitis C?
- C++ Program to find out if a round trip is possible from a particular city
- Program to find out if two expression trees are equivalent using Python
- Program to find out the path between two vertices in a graph that has the minimum penalty (Python)
- Program to find out if a BST is present in a given binary tree in Python
- C++ Program to find out if a palindromic matrix can be made from a given matrix
- Program to Find Out if There is a Short Circuit in Input Words in Python
- Find out when a download has completed using Python & Selenium
- How to find out who has checked my Facebook profile?
- Program to find out if the graph is traversable by everybody in Python