Answer to Question #269498 in C++ for ujoo

Question #269498

You are an inexperienced hacker trying to find the correct passcode to enter a safe.Write a program that defines the correct passcode of 246, and allows users to enter passcode attempts until they reach the correct number. Your program should use a while loop to allow the user to keep entering passcode attempts until correct and should use a break statement to exit the loop once the correct passcode is entered


1
Expert's answer
2021-11-21T04:49:14-0500
#include <iostream>
using namespace std;
int main(){
    int input = 0;
    while(true){
        cout<<"Enter passcode: ";
        cin>>input;
        if(input == 246) break;
        else{
            cout<<"Incorrect passcode!\n";
        }
    }
    cout<<"Correct!\n";
    return 0;
}

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