Thread: My setup() function is skipped.

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

    My setup() function is skipped.

    My setup() function is skipped. I am not able to enter 'y' for yes 'n' and proceed through the rest of the code inside this function. Instead when the program is run, it just jumps to the the following function, which is menu_and_startup().

    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    #include <time.h>
    
    void startup_message();
    void login_process();
    void setup();
    void menu_and_startup();
    void add_transferees();
    void view_transferees();
    void remit_money();
    void time_display();
    void display_information();
    void thank_you_message();
    
    int main ()
    {
        startup_message();
        
        login_process();
        
        menu_and_startup();
        
        return 0;
    }
    
    void startup_message()
    {
        printf("Welcome to the newly introduced smsTransfer© (remittances through SMS text messaging)!\n");
        printf("a joint project of PioneerBank and Globe Telecom\n");
        
        printf("NOTES:\n");
        printf("1. Both the transferers and the transferees must have active accounts with both companies to take part in this service.\n");
        printf("2. If this is your first time using the service, please add your account information immediately after logging into this service.\n\n");
    }
    
    void login_process()
    {
        char username[10];
        char correct_username[10];
        char second_part_of_correct_username[5];
        char firstname[10];
        char lastname[20];
        long long int cin;
        long long int correct_password;
        long long int password;
        short int attempts=0;
    
        printf("Enter your first name:\n");
        scanf("%s",firstname);
    
        strncpy(correct_username,firstname,2);
        correct_username[2]='\0';
    
        printf("Enter your last name:\n");
        scanf("%s",lastname);
    
        strncpy(second_part_of_correct_username,lastname,3);
        second_part_of_correct_username[3]='\0';
        strncat(correct_username,second_part_of_correct_username,5);
        
        printf("Enter your Customer Identification Number(CIN):\n");
        scanf("%llu",&cin);
        correct_password=(cin%10)+1;
        
        printf("Please note that usernames are case sensitive.\n");
        printf("Enter username:\n");
        scanf("%s",&username);
        
        printf("Enter password:\n");
        scanf("%llu",&password);
        
        if ((password==correct_password) && strcmp(username,correct_username)==0)
            {
                printf("Login successful!\n");
            }
        if ((password==correct_password) && strcmp(username,correct_username)==0)
            {
                FILE *file;
                file=fopen("account_information.txt","a");
                fprintf(file,"%s\t%llu\t",&username,&password);
                fclose(file);
            }
        if ((password==correct_password) && strcmp(username,correct_username)==0)
            {
                setup();
            }
        
        while ((password!=correct_password) || strcmp(username,correct_username)!=0)
            {
                printf("\nThe login details are invalid.Please try again.\n");
                
                printf("Enter username:\n");
                scanf("%s",&username);
    
                printf("Enter password:\n");
                scanf("%llu",&password);
                
                attempts++;
                
                if (attempts>=5)
                    printf("Too many failed login attempts. Please re-enter the program and attempt to complete the login process again.\n");
                if (attempts>=5)
                    exit(0);    
                
                if ((password==correct_password) && strcmp(username,correct_username)==0)
                    printf("Login successful!\n");
                if ((password==correct_password) && strcmp(username,correct_username)==0)
                    {
                        FILE *file;
                        file=fopen("account_information.txt","a");
                        fprintf(file,"%s\t%llu\t",&username,&password);
                        fclose(file);
                    }
                if ((password==correct_password) && strcmp(username,correct_username)==0)
                    setup();
            }
    }
    
    void setup()
    {
        char response;
        float current_balance;
        printf("Is this your first time using this service?\n");
        printf("Enter 'y' for yes or 'n' for no.\n");
        scanf("%c",&response);
        if (response=='y')
            printf("Enter the desired amount from the chequing account to be accessible by this service:$\n");
        if (response=='y')    
            scanf("%f",&current_balance);
        else 
            current_balance=0; 
        
        printf("%.2f",current_balance);         
    }
    
    void menu_and_startup()
    {
        short int option;
        do 
        {
        printf("\n___________________________________________\n");
        printf("1. Add transferees\n");
        printf("2. View current transferee list\n");    
        printf("3. Remit money\n");
        printf("4. Account information and settings\n");
        printf("5. Exit the application\n");
        printf("____________________________________________\n");
        printf("Please choose from the above options: \n");
        scanf("%d",&option);    
        switch(option)
            {
                case 1: add_transferees();
                        break;
                case 2: view_transferees();
                        break;
                case 3: remit_money();
                        break;
                case 4: display_information();
                        break;
                case 5:    thank_you_message();
                        exit(0);
            }
        } while(option>0 && option<6);
    }
    
    void add_transferees()
    {
      FILE *file;
      int i;
      char firstName[32];
      char lastName[32];
      char email_address[40];
      long long int account_number;
      long int phone_number;
      short int addchoice;
      int found = 0;
    
      file = fopen("transferee_list.txt", "a");
      if (!file)
      {
        printf("File could not be opened\n\a\a");
        getchar();
        exit(-1);
      }
      
      printf("Enter number of transferees you wish to add:\n");
      scanf("%d",&addchoice);
      
      for (i = 0; i<addchoice; ++i)
      {
        printf("Transferee #%d\n", i+1);
        
        printf("Enter first name:\n"); scanf("%s", &firstName);
        printf("Enter last name:\n"); scanf("%s", &lastName);
        printf("Enter PioneerBank account number:\n"); scanf("%llu", &account_number);
        printf("Enter e-mail address:\n"); scanf("%s", &email_address);
        printf("Enter Globe Telecom phone number:\n"); scanf("%lu",&phone_number);
        printf("\n");
    
        fprintf(file, "%s\t%s\t%llu\t%s\t%lu\n", firstName, lastName,account_number,email_address,phone_number);
      }
      
      printf("Transferee list successfully updated!\n");
      
      fclose(file);
    }
    
    void view_transferees()
    {
      char firstName[32];
      char lastName[32];
      char email_address[40];
      long long int account_number;
      long int phone_number;
      int counter=0;
      int found=0;
      
      FILE *file;
      file = fopen("transferee_list.txt", "r");
      if (!file)
      {
        printf("File could not be opened\n\a\a");
        exit(-1);
      }
    
      while (fscanf(file, "%s\t%s\t%llu\t%s\t%lu", &firstName,&lastName,&account_number,&email_address,&phone_number)==5)
        {
          printf("Transferee #%d:\n First Name:%s\n Last Name:%s\n Account Number:%llu\n E-mail address:%s\n Phone Number:%lu\n", counter, firstName, lastName, account_number, email_address, phone_number);
          
          found = 1;
        }
      
      if (!found)
        printf("Record could not be found");
    
      fclose(file);
    }
    
    void remit_money()
    {
        float current_balance;
        float transfer_amount;
        char transferee_name[70];
        
        printf("\nCurrent smsTransfer© balance:%.2f",current_balance);
        printf("Please enter the transferee's legal name (first & last only):");
        fgets(transferee_name,60,stdin);
        printf("Please enter the transferee's phone number:");
        printf("\nEnter the desired transfer amount:$");
        scanf("%.2f",&transfer_amount);
        
        if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)    
            current_balance-=transfer_amount;
        if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
            printf("Transaction approved! Your current balance is now $%.2f",current_balance);
        if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
            time_display();
        
        while (transfer_amount>=5000)
        {
            printf("In accordance with the Mobile Banking Act of 2024, customers are prohibited from sending amounts in excess of $1,000 per transaction.");
            printf("\nEnter the desired transfer amount:$");
            scanf("%.2f",&transfer_amount);
            
            if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)    
                    current_balance-=transfer_amount;
            if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
                    printf("Transaction approved! Your current balance is now $%.2f",current_balance);
            if (transfer_amount<5000 && transfer_amount<current_balance && current_balance-transfer_amount>=10000)
                    time_display();
        }    
    }
    
    void time_display()
    {
       time_t rawtime;
       struct tm *info;
       char buffer[80];
    
       time(&rawtime);
    
       info = localtime(&rawtime);
    
       strftime(buffer,80,"%A %B %d,%Y %H:%M (%Z)", info);
       printf("Transaction completed on: %s\n", buffer);
    }
    
    void display_information()
    {
        short int view_option;
        char address[150];
        long long int home_phone_number;
        long long int mobile_phone_number;    
    }
    
    void thank_you_message()
    {
        printf("Thanks for choosing and using smsTransfer©!\n");
    }

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    before running this you need to fix errors
    Code:
    src/test.c: In function ‘login_process’:
    src/test.c:64:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 2 has type ‘long long int *’ [-Wformat=]
         scanf("%llu",&cin);
         ^
    src/test.c:69:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[10]’ [-Wformat=]
         scanf("%s",&username);
         ^
    src/test.c:72:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 2 has type ‘long long int *’ [-Wformat=]
         scanf("%llu",&password);
         ^
    src/test.c:82:13: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char (*)[10]’ [-Wformat=]
                 fprintf(file,"%s\t%llu\t",&username,&password);
                 ^
    src/test.c:82:13: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘long long int *’ [-Wformat=]
    src/test.c:95:13: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[10]’ [-Wformat=]
                 scanf("%s",&username);
                 ^
    src/test.c:98:13: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 2 has type ‘long long int *’ [-Wformat=]
                 scanf("%llu",&password);
                 ^
    src/test.c:113:21: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char (*)[10]’ [-Wformat=]
                         fprintf(file,"%s\t%llu\t",&username,&password);
                         ^
    src/test.c:113:21: warning: format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘long long int *’ [-Wformat=]
    src/test.c: In function ‘menu_and_startup’:
    src/test.c:151:5: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘short int *’ [-Wformat=]
         scanf("%d",&option);
         ^
    src/test.c: In function ‘add_transferees’:
    src/test.c:189:3: warning: format ‘%d’ expects argument of type ‘int *’, but argument 2 has type ‘short int *’ [-Wformat=]
       scanf("%d",&addchoice);
       ^
    src/test.c:195:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[32]’ [-Wformat=]
         printf("Enter first name:\n"); scanf("%s", &firstName);
         ^
    src/test.c:196:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[32]’ [-Wformat=]
         printf("Enter last name:\n"); scanf("%s", &lastName);
         ^
    src/test.c:197:5: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 2 has type ‘long long int *’ [-Wformat=]
         printf("Enter PioneerBank account number:\n"); scanf("%llu", &account_number);
         ^
    src/test.c:198:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘char (*)[40]’ [-Wformat=]
         printf("Enter e-mail address:\n"); scanf("%s", &email_address);
         ^
    src/test.c:199:5: warning: format ‘%lu’ expects argument of type ‘long unsigned int *’, but argument 2 has type ‘long int *’ [-Wformat=]
         printf("Enter Globe Telecom phone number:\n"); scanf("%lu",&phone_number);
         ^
    src/test.c:178:7: warning: unused variable ‘found’ [-Wunused-variable]
       int found = 0;
           ^
    src/test.c: In function ‘view_transferees’:
    src/test.c:228:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘char (*)[32]’ [-Wformat=]
       while (fscanf(file, "%s\t%s\t%llu\t%s\t%lu", &firstName,&lastName,&account_number,&email_address,&phone_number)==5)
       ^
    src/test.c:228:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘char (*)[32]’ [-Wformat=]
    src/test.c:228:3: warning: format ‘%llu’ expects argument of type ‘long long unsigned int *’, but argument 5 has type ‘long long int *’ [-Wformat=]
    src/test.c:228:3: warning: format ‘%s’ expects argument of type ‘char *’, but argument 6 has type ‘char (*)[40]’ [-Wformat=]
    src/test.c:228:3: warning: format ‘%lu’ expects argument of type ‘long unsigned int *’, but argument 7 has type ‘long int *’ [-Wformat=]
    src/test.c: In function ‘remit_money’:
    src/test.c:252:5: warning: unknown conversion type character ‘.’ in format [-Wformat=]
         scanf("%.2f",&transfer_amount);
         ^
    src/test.c:252:5: warning: too many arguments for format [-Wformat-extra-args]
    src/test.c:265:9: warning: unknown conversion type character ‘.’ in format [-Wformat=]
             scanf("%.2f",&transfer_amount);
             ^
    src/test.c:265:9: warning: too many arguments for format [-Wformat-extra-args]
    src/test.c: In function ‘display_information’:
    src/test.c:295:19: warning: unused variable ‘mobile_phone_number’ [-Wunused-variable]
         long long int mobile_phone_number;
                       ^
    src/test.c:294:19: warning: unused variable ‘home_phone_number’ [-Wunused-variable]
         long long int home_phone_number;
                       ^
    src/test.c:293:10: warning: unused variable ‘address’ [-Wunused-variable]
         char address[150];
              ^
    src/test.c:292:15: warning: unused variable ‘view_option’ [-Wunused-variable]
         short int view_option;
                   ^
    src/test.c: In function ‘remit_money’:
    src/test.c:247:11: warning: ‘current_balance’ is used uninitialized in this function [-Wuninitialized]
         printf("\nCurrent smsTransfer© balance:%.2f",current_balance);
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  3. #3
    Registered User
    Join Date
    Apr 2015
    Posts
    33
    I didn't see any warning messages when I compiled the program using code::blocks.
    Last edited by howardbc14; 05-14-2015 at 10:56 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,666
    You need to add the -Wall to your compiler options to get lots of useful diagnostic.
    My setup() function is skipped.-code_blocks_wall-png
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. gets function skipped 1st time
    By ambrown782 in forum C Programming
    Replies: 6
    Last Post: 07-26-2014, 12:30 AM
  2. gets() skipped!
    By ncode in forum C Programming
    Replies: 14
    Last Post: 02-06-2012, 05:01 PM
  3. Scanf Being skipped
    By GibsMe in forum C Programming
    Replies: 2
    Last Post: 10-11-2009, 03:23 PM
  4. Second scanf keeps getting skipped.
    By yougene in forum C Programming
    Replies: 9
    Last Post: 12-23-2008, 02:39 AM
  5. Unsure of how to setup this function
    By Khem101 in forum C Programming
    Replies: 4
    Last Post: 10-03-2006, 07:32 AM