#include <conio.h>
#include <stdio.h>
#include <windows.h>



void display(void);
void menu(void);

int main()
{
    
    char username[9];
    int password=0,x=1;
    
    
    display();
    
    
    do
    {
                 
                  
                  printf("\n\t\t\tPlease enter your username:");
                  scanf("%s",username);
    
                 
                  printf("\n\n\t\t\tPlease enter your password:");
                  scanf("%d",&password);

                          //problem
                           if (username == 'udental' &&  password == 1987)
                                menu();
                           else 
                            {
                                printf("\n\n\t\t\t YOU HAVE MADE AN INVALID INPUT");
                                printf("\n\n\t\t\t      PLEASE TRY AGAIN\n\n"); 
                                Sleep (1000);
                                system("cls");
                            }
                  
                  
                  
                  
                  x++;
                  
     }while(x<4);             
    
     printf("\n\n\n\t\tSORRY BUT YOU HAVE ENTERED INCORRECT INFORMATION");
     printf("\n\n\t\t\t      GOODBYE");
      
     
    
    
    
    getch();
    return 0;
}

void display(void)
{
     
     
     printf("\n\n\t\t\tSMILES DENTAL CENTRE\n\n");
     printf("\n\n\t\t    WHERE YOU GET THE PERFECT SMILE\n\n");
     printf("\n\n\n\n\t\t       PRESS ENTER TO CONTINUE");
     getchar();
     system("cls");     
         
}

void menu(void)
{
     
     printf("\n\n\t\tWELCOME TO THE SYSTEM MENU");
     printf("\n\n\t\t   PLEASE SELECT YOUR OPTION BELOW");
}

Edited 6 Years Ago by WaltP: Youve been told about them. You've refused to use them. And we can't help without knowing what the problem is.

I don't know what the problem is, but I see two glaring problems.

  1. scanf("%s", username); -- what happens if someone enters 20 characters as the user name? A: Program will most likely crash because username can only hold 8 characters. Solution: use fgets() instead of scanf() because fgets() will limit the input to the size of the buffer.
  2. scnaf("%d", &password); -- what happens of someone enters text instead of numeric data? A: the password will not be changed. Solution: Make the password a text array.

Edited 6 Years Ago by Ancient Dragon: n/a

You cannot write

username == 'udental'

It's not that he cannot write it. Technically speaking, it's not a syntax error but it will always be evaluated to false.
(At least my Code::Blocks compiler tells me that)

As per my knowledge, we are trying to check the equality of two char pointers of two different strings (which is always different). Hence always false

@HBK_100 #include <conio.h> Argh! The infernal and vile conio.h, please trash it! There are many alternatives to getch() And also try to avoid system calls. They are
1) Slow
2) Risky to use
3) Reduces portability of your code

@HBK_100

Unfortunately, you're wasting your time. Read his/her user title.

Edited 6 Years Ago by jonsca: n/a

This article has been dead for over six months. Start a new discussion instead.