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
#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;
}
Comments
Leave a comment