# Help in Turbo C



## kumagpoko (Aug 6, 2007)

i have problem in my program....when i enter my name kumagpoko..it displays name denied but it should be accepted...how can i fix this??? and one more... how can i put loop to "please enter your name" when i try to input a wrong name....

*tnx for the help... 
*
*



#include <stdio.h>

main()

{
int name;

printf("\n Welcome to Login Screen\n\n\n\n");

printf("Please enter your name:\n");
scanf("%s",&name);

if (name=="kumagpoko")
{
printf("Name Accepted");
}
else
{
printf("Name Denied");
}

getch();
}

Click to expand...

*


----------



## Shadow2531 (Apr 30, 2001)

You don't want name to be an int.
You want "char name[200]" for example.

In string.h is strcmp. For example, strcmp("a", "a") would return 0 since they're the same.

For a loop, you can start off with a continous loop. Then, break if you want out.
for ( ; ; ) {
break;
}

After using scanf, you might want to fflush(stdin) to clear the input buffer so your getch doesn't suck in any characters that are still in the buffer.

Instead of getch, use getchar() and press ENTER to exit instead of just any key.

main() has a type. It should be int and it should return an int.


----------



## kumagpoko (Aug 6, 2007)

i dont understand and i dont know how to use "for" and "break" commands....T_T

btw heres my program now...

can u plss put the loop command....T_T...both in name and surname

*



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

int main()

{

char name[20];
char surname[20];
clrscr();

textcolor(GREEN);

cprintf("\n\n\n\n\n\n *** Welcome to LogIn screen ***\n\n\n");

printf("\n Enter Your Name:");

gets(name);

if (!strcmp(name,"miko"))

{textcolor(YELLOW); cprintf("\n Name Accepted!"); }

else
{ textcolor(RED);

cprintf("\n Please Enter Again"); }

printf("\n Enter Your Surname: ");

gets(surname);
if(!strcmp(surname,"siriban"))

{textcolor(YELLOW); cprintf("\n Surname Accepted!"); }

else

{textcolor(RED);
cprintf("\n Surname Denied"); }

getchar();
}

Click to expand...

*


----------



## mt2002 (Sep 14, 2005)

Jees.. I havn't used TurboC in some time 

Anyways:

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

int main()
{

   char name[20];
   char surname[20];
   int iTries=0;     /* index var */
   clrscr();

   textcolor(GREEN);

   cprintf("\n\n\n\n\n\n *** Welcome to LogIn screen ***\n\n\n");

   for (iTries=0; iTries<=5; iTries++) {   /* loop until i<=5. 5 attempts to login */

      printf("\n Enter Your Name:");
      gets(name);

      if (!strcmp(name,"miko"))
     {
         textcolor(YELLOW);
         cprintf("\n Name Accepted!");
         break;         /* name is good, so break out of loop */
     }
     else
     { 
        textcolor(RED);
        cprintf("\n Please Enter Again\n");
     }
   }

  /** If iTries==5 and name is still not correct, all attempts failed **/

   getchar();
}
```
Code was not tested nor compilied.


----------



## kumagpoko (Aug 6, 2007)

^

thank you very much dude...its working now....=]

but after i enter my name correctly...the program stop there....how about in the surname???T_T

i compile this and i got 1 error.. "misplace break in function main"... i cant figure it out...T_T
*
this is just a guess for surname...=]
*

*pls edit it because some codes are wrong..*

EDIT~~~

ok i figure out what to do in surname...tnx to all who helped me...*cheers*

im preparing to defend this program...pray for me....=[


----------

