#include<iostream>
usingnamespace std;
int main()
{
int temp;
cout <<"Enter the desire temperature: ";
cin>>temp;
int lowerTemp=temp;
int onesDigit=temp%10; //First digit
int tensDigit=(temp/10)%10;//Second digit
int hundredsDigit=temp/100;//Third digit
while ((onesDigit==1)||(onesDigit==4)||(onesDigit==7)||
(tensDigit==1)||(tensDigit==4)||(tensDigit==7)||
(hundredsDigit==1)||(hundredsDigit==4)||(hundredsDigit==7))
{
lowerTemp--;
onesDigit=lowerTemp%10;
tensDigit=(lowerTemp/10)%10;
hundredsDigit=lowerTemp/100;
}
int higherTemp=temp;
onesDigit=higherTemp%10;
tensDigit=(higherTemp/10)%10;
hundredsDigit=higherTemp/100;
while ((onesDigit==1)||(onesDigit==4)||(onesDigit==4)||
(tensDigit==1)||(tensDigit==4)||(tensDigit==7)||
(hundredsDigit==1)||(hundredsDigit==4)||(hundredsDigit==7))
{
higherTemp++;
onesDigit=higherTemp%10;
tensDigit=(higherTemp/10)%10;
hundredsDigit=higherTemp/100;
}
cout<< "The closest higher temperature is :"<<higherTemp<<endl;
cout<< "The closest lower temperature is :"<<lowerTemp<<endl;
return 0;
}
i need to add bool containsDigit(int number, int digit);
to the working program and still get the same output.
how would that work?