Thread: I keep getting an auto-generated number when I run the program.

  1. #1
    Registered User
    Join Date
    Apr 2015
    Posts
    33

    I keep getting an auto-generated number when I run the program.

    I want actual_password to be equivalent to cin/1000. I have specified this and the result is a randomly generated number.

    For example if I type in 1000 for cin, actual_password is not equal to 1.

    Code:
    #include <stdio.h>
    #include <string.h>
    
    int main ()
    {
        char first_part_of_username[10];
        char second_part_of_username[10];
        char username[10];
        long long int cin;
        long long int password;
        long long int actual_password;
    
        char first_name[15];
        char last_name[15];
        
        printf("WELCOME TO gotransfer A JOINT PROJECT OF METROPOLITAN BANK IN PARTNERSHIP WITH GLOBE TELECOM!!!\n\n");
        printf("NOTE: PRIOR REGISTRATION WITH BANK REPRESENTATIVES IS NECESSARY PRIOR TO SIGNING IN THROUGH THIS PROGRAM.\n");
        printf("PLEASE ENTER THE FOLLOWING.\n");
        
        printf("FIRST NAME:\n");
        scanf("%s",first_name);
        
        strncpy(first_part_of_username,first_name,2);
        first_part_of_username[2]='\0';
        
        printf("LAST  NAME:\n");
        scanf("%s",last_name);
        
        strncpy(second_part_of_username,last_name,1);
        second_part_of_username[1]='\0';
        strncat(first_part_of_username,second_part_of_username,3);
        printf("CUSTOMER IDENTIFIER NUMBER:");    
        scanf("%d",&cin);
        actual_password=(cin/1000);
        printf("LOGIN DETAILS\n");
        
        printf("Username:\n");
        scanf("%s",&username);
        
        printf("Password:\n");
        scanf("%d",&password);
        printf("The correct password is %d",&actual_password);
        if ((password,actual_password)==0 && strcmp(first_part_of_username,username)== 0)
        {printf("Login successful.\n\n");}
        else
        {printf("Login unsuccessful. Please try again.\n\n");}
        return 0;
    }

  2. #2
    Registered User
    Join Date
    Mar 2012
    Location
    the c - side
    Posts
    373
    Time to enable your compiler warnings.

    Code:
    ||=== Build: Debug in test (compiler: GNU GCC Compiler) ===|
    C:\Users\HP Pavilion\C Programs\test\main.c||In function 'main':|
    C:\Users\HP Pavilion\C Programs\test\main.c|33|warning: format '%d' expects argument of type 'int *', but argument 2 has type 'long long int *' [-Wformat]|
    C:\Users\HP Pavilion\C Programs\test\main.c|38|warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[10]' [-Wformat]|
    C:\Users\HP Pavilion\C Programs\test\main.c|41|warning: format '%d' expects argument of type 'int *', but argument 2 has type 'long long int *' [-Wformat]|
    C:\Users\HP Pavilion\C Programs\test\main.c|43|warning: left-hand operand of comma expression has no effect [-Wunused-value]|
    ||=== Build finished: 0 error(s), 4 warning(s) (0 minute(s), 0 second(s)) ===|

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 11-20-2013, 01:34 PM
  2. Auto generated ID
    By ulti-killer in forum C Programming
    Replies: 3
    Last Post: 10-13-2012, 02:04 AM
  3. [VS 2005] Auto generated skeleton code
    By cboard_member in forum Tech Board
    Replies: 4
    Last Post: 03-06-2006, 12:45 PM
  4. Replies: 1
    Last Post: 03-17-2005, 08:53 AM
  5. Auto generated
    By Daniel decosta in forum C Programming
    Replies: 11
    Last Post: 09-28-2002, 05:35 PM