Answer to Question #331392 in C++ for Ness

Question #331392



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 a space.

1
Expert's answer
2022-04-20T12:40:29-0400
#include <iostream>

using namespace std;

bool check3dig(int n)
{
	int i = 0;
	while (n > 0)
	{
		n /= 10;
		i++;
	}
	if (i == 3)return true;
	else return false;
		
}

int main()
{
	int x, y;
	cout << "Please, enter the first digit: ";
	cin >> x;
	if (!check3dig(x))
	{
		cout << "First number must have 3 digit!";
	}
	else
	{
		cout << "Please, enter the second digit: ";
		cin >> y;
		if (!check3dig(y))
		{
			cout << "Second number must have 3 digit!";
		}
		else
		{
			if (x == y)
				cout << "Jackpot!";
			else
				cout << "Nah";
		}
	}
	
}





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS