Did you know that in lotteries, a 3-digit number with the same numbers in all digits like 777 will hit the jackpot in a casino? In the same manner, let's make a program that will test if a certain 3-digit number hits a jackpot or not by identifying if all the digits of a given number is the same as the second inputted number. If it is, print "Jackpot!"; else, print "Nah".
Let's try this out now!
Input
A line containing two integers separated by two input.
Enter 3-digit integer :777
Enter second digit to be searched 0-9):7
Output
A line containing a string.
Jackpot!
//Test to online compiler
#include <iostream>
#include <iomanip>
using namespace std;
//JackPOT
//Define a function wich will check is all digit same
bool isJackpot(int numTreeDig,unsigned secDig)
{
  //@numTreeDig-Tree digit number 
  //@secDig-second digit wich user will enter 
  while(numTreeDig!=0)
    {
      if(secDig!=numTreeDig%10)
        return  false;
      numTreeDig/=10;
    }
  return true;
}
int main()
{
  cout<<"Enter 3-digit integer:";
  int num=0;
    cin>>num;
  if(num>99&&num<1000)
  {
    cout<<"Enter second digit to search 0-9):";
    unsigned sec;
    cin>>sec;
    if(sec/10!=0)
    {
      cout<<"Incorrect input\n";
    }
    else
    {
      if(isJackpot(num,sec))
        cout<<"Jackpot!"<<endl;
      else
        cout<<"Nah\n";
    }
  }
  else
    cout<<"Incorrect input please try again!\n";
  return 0;
}
Comments