Computing Staff
  • 1

Break Statement Is Not Within Loop Or Switch

  • 1

i’m still new with c program and language, i’m learning it by myself.
can anyone tell my why it state that break statement is not within loop or switch.

#include <stdio.h>
#include <string.h>

int main()
{
char password[14] = “student14”;
char input_user[14];
char name[20];
char system;
char security_code[20] = “270792”;
char input_security[20];
int x;
int y;

printf(“Please input your name and password. \n”);
printf(“Name:”);scanf(“%[^\n]”, name);
fflush(stdin);

for (x = 0; x < 3; x++)
{
printf(“Password:”);scanf(“%[^\n]”, input_user);
fflush(stdin);

if (strcmp (input_user, password) == 0)
break;
else
printf(“Access Denied\n”);

}

if (strcmp (input_user, password) == 0)
{
printf(“Access Granted”);

}
else
{
for (y = 0; y < 10; y++);
{
printf(“Please input your security code\n”);
printf(“Security Code: “);scanf(“%[^\n]”, input_security);

if (strcmp (input_security, security_code) == 0)
break;
else
printf(“Access Denied\n”);

}
}

printf(“Access Granted.\nCongratulation you finaly able to enter you program.”);

getchar();
fflush(stdin);
return 0;
}

Share

1 Answer

  1. The semi-colon at the end of the second “for” statement is an error as it produces an empty “for” loop.

    • 0