Holy digits Batman! The Riddler is planning his next caper somewhere on Pennsylvania Avenue. In his usual sporting fashion, he has left the address in the form of a puzzle. The address on Pennsylvania is a four-digit number where: • All four digits are different • The digits in the thousandths place is three times the digit in the tens place • The number is odd • The sum of the digits is 27 Write a program that uses a loop (or loops) to find the address where the Riddler plans to strike.
I'm not so sure where the program is going wrong. any help will be appreciated.
#include <iostream>
using namespace std;
void splitAddress(int address, int thou, int hund, int tens, int ones) {
while (address >= 1000) {
address = address - 1000;
thou++;
}
while (address >= 100) {
address = address - 100;
hund++;
}
while (address >= 10) {
address = address - 10;
tens++;
}
while (address >= 1) {
address = address - 1;
ones++;
}
}
void areIntsTheSame(int address, int thou, int hund, int tens, int ones) {
if (thou == hund || thou == tens || thou == ones ||
hund == tens || hund == ones || tens != ones) {
address--;
}
}
void thou3tens(int address, int thou, int tens) {
if (thou != 3 * tens) {
address--;
}
}
void evenOrOdd(int address) {
if (address % 2 == 0) {
address--;
}
}
void Sum27(int address, int thou, int hund, int tens, int ones) {
if ((thou + hund + tens + ones) != 27) {
address--;
}
}
int main() {
int address = 9999;
int thou = 0;
int hund = 0;
int tens = 0;
int ones = 0;
splitAddress(address);
areIntsTheSame(address);
thou3tens(address);
evenOrOdd(address);
Sum27(address);
cout << "the address is " << address << endl;
system("pause");
return 0;
}
thanks in advance.
Aucun commentaire:
Enregistrer un commentaire