0% found this document useful (0 votes)
5 views2 pages

Cos Assignment

Uploaded by

darasimiadesida8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Cos Assignment

Uploaded by

darasimiadesida8
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

BABCOCK UNIVERSITY

COS 101 ASSIGNMENT

MATRIC NO: 24/1530


ADESIDA ADWEMIMO OLUWADARASIMI
GROUP A SOFTWARE ENGINEERING
// Program to allow user to key in a passcode with 3 attempts
// Written by: [ADESIDA ADEWEMIMO OLUWADARASIMI]
// Matriculation Number: [24/1530]
#include <stdio.h>
#include <string.h>
int main() {
const char correct_passcode[] = "1234"; // Set the correct passcode
here
char user_input[20]; // To store user input
int max_attempts = 3; // Maximum number of attempts
int attempts = 0; // Count of attempts made
while (attempts < max_attempts) {
printf("Enter your passcode: ");
scanf("%6s", user_input); // Get user input (max 6 characters to
prevent overflow)
if (strcmp(user_input, correct_passcode) == 0) {
printf("Access Granted!\n");
return 0; // Exit the program successfully
} else {
attempts++;
printf("Incorrect passcode. You have %d attempt(s) left.\n",
max_attempts - attempts);
}
}

// If the loop ends, it means all attempts failed


printf("Access Denied. Program terminated after 3 failed attempts.\n");
return 1; // Exit with error code
}

You might also like