This should be solved in the riddle.cpp file. Holy digits Batmans! The Riddler i
ID: 3690977 • Letter: T
Question
This should be solved in the riddle.cpp file. Holy digits Batmans! The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his usually sporting fashion, he has left the address in the form of a puzzle. The address on Pennsylvania is a four-digit number where: 1. All four digits are different 2. The digit in the thousands place is three times the digit in the tens place 3. The number is odd 4. The sum of the digits is X, where X is from the user input Write a program that uses a loop (or loops) to find the address where the Riddler plans to strike. The program should print a string of text to the terminal before getting X from the user, and then it should print all the possible numbers in increasing order with one number per line. If no such number exists for the given input, then it should print "No such number exists." A session should look like the following example (including whitespace and formatting), with possibly different inputs and numbers in the output: Enter the sun of digits X (or zoro to quit): 9 The possible address(es) is(are): 3015 6021 Enter the sun of digits X (or zero to quit): 11 The possible address(es) is(are): 3017 3215 6023 Enter the sun of digits X (or zero to quit): 27 The possible address(es) is(are): 9837 Enter the sun of digits X (or zero to quit): 33 The possible address(es) is(are): No such number exists. Enter the sun of digits X (or zero to quit): 0 Each string printed by the program should include a newline at the end, but no other trailing whitespace.Explanation / Answer
#include <iostream>
using namespace std;
int main() {
// your code goes here
int i=0,j=0,k=0,l=0;
int num=0,x=0,sum=0;
cout<<"Enter the sum of digits X(or Zero quit): ";
cin>>x;
if(x!=0){
cout<<" Possible ways ";
for(l=1;l<=9;l++){
for(i=0;i<=9;i++){
for(k=1;k<4;k++){
for(j=0;j<=9;j++){
if(l == k*3){
sum = l + j + k +i;
if(sum == x && l!=j && l!=k && l!=i && j!=i && j!=k && k!=i){
num = l*1000 + i*100 + k*10 + j;
if(num%2==1)
cout<<num<<endl;
}
}
}
}
}
}
}
return 0;
}
output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.