Solved Break statement is not within loop or switch

November 19, 2014 at 08:32:36
Specs: Windows 7
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;
}



See More: Break statement is not within loop or switch

Report •

#1
November 19, 2014 at 08:48:18
✔ Best Answer
The semi-colon at the end of the second "for" statement is an error as it produces an empty "for" loop.

message edited by ijack


Report •

#2
November 19, 2014 at 09:51:23
Thank you sir, now i can finally compile it.

Report •
Related Solutions


Ask Question