Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

check out for mistake, its not running..

+1 vote
asked Jul 10, 2019 by ishuRastogi (130 points)
#include <stdio.h>
#include <string.h>

int main()
{
    char user_id[]="ishurastogi2001", pass[]="ishu2001", a[15], b[8];
    int x,y;
    x=strcmp(a, user_id);
    y=strcmp(b, pass);
    for(int n=1; n<=3; n++)
    {
        printf("Enter User ID:");
        scanf("%s ", user_id);
        if(x==0)
        {
            printf("Enter user password: ");
            scanf("%d ", pass);
            if(y==0)
            {
                printf("You are logged in...");
            }
            else
            {
                printf("Incorrect Password, try again...");
            }
        }
        else
        {
            printf("Invalid User Id...");
        }
        if(n>5)
        {
            printf("Access Denied...");
        }

    }
    return 0;
}

2 Answers

0 votes
answered Jul 11, 2019 by anonymous 1 flag

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

int main()
{
    char user_id[]="ishurastogi2001", pass[]="ishu2001", a[15], b[8];
    int x,y;
    x=strcmp(a, user_id);
    y=strcmp(b, pass);
    for(int n=1; n<=3; n++)
    {
        printf("Enter User ID:");
        scanf("%s ", user_id);
        if(x==0)
        {
            printf("Enter user password: ");
            scanf("%d ", pass);
            if(y==0)
            {
                printf("You are logged in...");
            }
            else
            {
                printf("Incorrect Password, try again...");
            }
        }
        else
        {
            printf("Invalid User Id...");
        }
        if(n>5)
        {
            printf("Access Denied...");
        }

    }
    return 0;

0 votes
answered Jul 11, 2019 by Loki (1,600 points)
edited Jul 11, 2019 by Loki
I'd suggest you first remove the space in the scanf command after %s and %d. Also you need to change the %d to %s as you are using alphanumeric password(having alphabets also) and you should scanf 'a' instead of 'user_id' and 'b' instead of 'pass' furthermore you must do a strcmp after user has input the values or else it will always be incorrect. The correct code is below:

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

int main()
{
    char user_id[16]="ishurastogi2001", pass[]="ishu2001", a[16], b[9];
    int x,y;
    x=strcmp(a, user_id);
    y=strcmp(b, pass);
    for(int n=1; n<=3; n++)
    {
        printf("Enter User ID:");
        scanf("%s", &a);
        x=strcmp(a, user_id);
        if(x==0)
        {
            printf("Enter user password: ");
            scanf("%s", &b);
            y=strcmp(b, pass);
            if(y==0)
            {
                printf("You are logged in...");
            }
            else
            {
                printf("Incorrect Password, try again...");
            }
        }
        else
        {
            printf("Invalid User Id...");
        }
        if(n>5)
        {
            printf("Access Denied...");
        }

    }
    return 0;
}

The code above will ask you the user name and if correct then pass. It will continue to ask three times even if correct thus I advise to use a break statement.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...