Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The keypad on your oven is used to enter the desired baking temperature and is a

ID: 673177 • Letter: T

Question

The keypad on your oven is used to enter the desired baking temperature and is arranged like the digits on a phone. Unfortunately, the digits 1, 4, and 7 do not work.

When a recipe calls for a temperature that can't be entered (due to keys not working), you want to substitute a temperature that can be entered.

Write a program that takes a desired temperature as an input from the user. The temperature must be between 0 and 999 degrees.

If the desired temperature does not contain 1, 4, or 7, then display the desired temperature. If it contains 1, 4, or 7, compute and display the next largest temperature that doesn't contain 1, 4, or 7.

For example, if the desired temperature is 450, then the program should output 500. Similarly, if the desired temperature is 375, then the program should output 380.

In your program, include and use a function named "containsDigit" declared as below. If the entered number contains a digit, the function should return true. Otherwise, the function should return false.

bool containsDigit(int number, int digit)

1 2 3 4 5 6 7 8 9 0

Explanation / Answer

bool containsDigit(int number, int digit){
   while(number > 0){
       int d = number%10;
       number/=10;
       if( d == digit) return true;
   }
   return false;
}


int main(){
   int temp;
   cin >> temp;

   while(temp <= 999){
       if(containsDigit(temp,1) || containsDigit(temp,4) || containsDigit(temp,7))
           temp += 1;
       else
           {
               cout << temp << endl;
               break;
           }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote