Thread: Jump to another function

  1. #1
    Registered User
    Join Date
    Jun 2012
    Posts
    127

    Jump to another function

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    
    // number of salesman 
    #define SIZE 100
    // salesman_type structure definition
    typedef struct{
            //int ID; // salesman id
            char id_txt[6]; // salesman id for txt file
            char name[50]; // salesman name
            double hor_total; // total sales amount of a salesman  
        }salesman_type; // end structure salesman_type
    
    
    // function prototype
    void sale_menu(int *menu); 
    void report_menu(int *report); 
    void deleteSales(int *newId);
    void setting(int *tip, int *year);
    
    
    // sales processing system menu function
    void sale_menu(int *menu)
    {
        system("cls");
        printf("Sales Processing System\n");
        printf("-----------------------\n\n");
        printf("1. Add Salesman Records\n");
        printf("2. Reports Generation\n");
        printf("3. Modify Salesman Records\n");
        printf("4. Delete Salesman Records\n");
        printf("5. Change Settings\n\n");
        printf("0. Exit\n");
        printf("Your choice: ");
        scanf("%d", menu);
        system("cls");
    }// end function sale_menu
    
    
    // reports generation menu function
    void report_menu(int *report)
    {
        system("cls");
        printf("Reports Generation\n");
        printf("------------------\n\n");
        printf("1. View Quarterly Sales Report\n");
        printf("2. View Individual Salesman Commission\n\n");
        printf("0. Return to Main Menu\n");
        printf("Your choice: ");
        scanf("%d", report);
        system("cls");
    }// end function report_menu
    
    
    // delete salesman records function
    void deleteSales(int *newId)
    {
        int loop = 1, b, del;// counter 
        char buffer[100]; // buffer data from one text file to another
    
    
        // display title
        printf("Delete Salesman Records\n");
        printf("=======================\n");
    
    
    
    
                // prompt and read salesman id
                printf("Salesman ID (NO.): ");
                scanf("%d",&del);
    
    
                // if out of modify salesman record range
                if (del > *newId)
                {
                    printf("No record found.\n");
    
    
                    printf("\nPress Enter to continue...\n"); 
                    getchar(); 
                    getchar(); // prompt user;
                    
                }
                else
                {
                    // while it is not the targeted salesman id
                    while (loop < del)
                    {
                        // increment loop
                        loop++;
                    } // end while
    
    
                    if (del < *newId)
                    {    
                    } // end while
                
                    // display message 
                    printf("\n\nRecord deleted.\n");
                    system("pause");
                } // end else
            
    }// end function deleteSales
    
    
    // change setting function
    void setting(int *getSet, int *chgTip, int *chgYear)
    {
        // setting.ini file pointer
        FILE *setPtr;
    
    
        // preset setting
        char preset[4] = "ON"; 
        // reset input buffer
        int ch; 
    
    
        // clear screen display
        system("cls");
    
    
        // if tip is not equal to 1, set the preset to OFF
        if (*chgTip != 1)
            strcpy(preset,"OFF");
            
        // display title
        printf("Settings\n");
        printf("--------\n\n");
        printf("1. Tips Notification: %s\n", preset);
        printf("2. Change Year\n\n");
        printf("0. Return to Main Menu\n");
        printf("Your choice: ");
        scanf("%d", getSet);
        
        // set to OFF status if user change the tip setting
        if (*getSet == 1)
        {
            // if the setting is ON
            if (*chgTip == 1)
            {
                // set preset to OFF
                strcpy(preset,"OFF");
    
    
                // set tip to zero 
                (*chgTip)--;
    
    
                // open setting.ini in writing mode
                if ( (setPtr = fopen("setting.ini","r")) == NULL)
                { 
                    printf("Cannot open setting.ini.\n");
                    system("pause");
                    exit(-1);
                }
                else
                {
                    // read year value
                    fscanf(setPtr,"%*[^\n]\n%*[^=]=%d",&(*chgYear));
                    // close setting.ini
                    fclose(setPtr);
    
    
                    // open setting.ini in writing mode
                    if ( (setPtr = fopen("setting.ini","w")) == NULL)
                    {
                        printf("Cannot writting file to system. Check the system.\n");
                        system("pause");
                        exit(-1);
                    } // end if
                    else
                    {
                        // write tip value
                        fprintf(setPtr,"tip = %d\n",*chgTip);
                        // write year value
                        fprintf(setPtr,"year = %d",*chgYear);
                    } // end else
    
    
                    // close setting.ini
                    fclose(setPtr);
                } // end else
            } // end if
            else
            {
                strcpy(preset,"ON");
                (*chgTip)++;
    
    
                // open setting.ini in writing mode
                if ( (setPtr = fopen("setting.ini","r")) == NULL)
                { 
                    printf("Cannot open setting.ini.\n");
                    system("pause");
                    exit(-1);
                }
                else
                {
                    // read year value
                    fscanf(setPtr,"%*[^\n]\n%*[^=]=%d",&(*chgYear));
                    // close setting.ini
                    fclose(setPtr);
    
    
                    // open setting.ini in writing mode
                    if ( (setPtr = fopen("setting.ini","w")) == NULL)
                    {
                        printf("Cannot writting file to system. Check the system.\n");
                        system("pause");
                        exit(-1);
                    } // end if
                    else
                    {
                        // write tip value
                        fprintf(setPtr,"tip = %d\n",*chgTip);
                        // write year value
                        fprintf(setPtr,"year = %d",*chgYear);
                    } // end else
    
    
                    // close setting.ini
                    fclose(setPtr);
                } // end else
            } // end else
        } // end if
        
        // clear display buffer
        system("cls");
    
    
        // change year
        if (*getSet == 2)
        {
            printf("Year: ");
            scanf("%d",&(*chgYear));
    
    
            // open setting.ini in writing mode
            if ( (setPtr = fopen("setting.ini","r")) == NULL)
            { 
                printf("Cannot open setting.ini.\n");
                system("pause");
                exit(-1);
            }
            else
            {
                // read year value
                fscanf(setPtr,"%*[^=]=%d",&(*chgTip));
                // close setting.ini
                fclose(setPtr);
    
    
                // open setting.ini in writing mode
                if ( (setPtr = fopen("setting.ini","w")) == NULL)
                {
                    printf("Cannot writting file to system. Check the system.\n");
                    system("pause");
                    exit(-1);
                } // end if
                    else
                    {
                        // write tip value
                        fprintf(setPtr,"tip = %d\n",*chgTip);
                        // write year value
                        fprintf(setPtr,"year = %d",*chgYear);
                    } // end else
    
    
                    // close setting.ini
                    fclose(setPtr);
                } // end else
        } // end if
    
    
        // clear display buffer
        system("cls");
    
    
    
    
    } // end function setting
    
    
    // function main begins program execution
    int main()
    {
        // variable declaration
        int a, b, c = 0, last; // counter
        int getMenu = 10, getReport = 10, getSet = 10; // menu selector
        double ver_total = 0, max = 0; 
        int lastId; // last saved salesman id
        int tip; // tip setting
        int year; // year setting
        int resetId = 0; // pass value execute assignment of nextId function
    
    
        // while the user input is not zero
        while (getMenu != 0)
        {
            // call sale_menu function, prompt and read user input
            sale_menu(&getMenu);
    
    
            // Execute function based on user input
            switch(getMenu)
            {
                
                case 1:
                    break;
                // call report_menu function
                case 2:
                    // Call report_menu,prompt and read user input
                    report_menu(&getReport);
                    break;
                case 3:
                    break;
                case 4:
                    // call deleteSales function
                    deleteSales(&lastId);
                case 5:
                    // call setting function
                    setting(&getSet, &tip, &year);
    
    
                    // loop the function until user exit the function
                    while (getSet != 0)
                    {
                        setting(&getSet, &tip, &year);
                    }
    
    
            } // end switch
        }// end while 
        return 0; // end program 
    } // end main
    Input 4 then 4.
    Why it straight away jump to setting function ?

  2. #2
    Registered User
    Join Date
    Jun 2012
    Posts
    127
    I forget to put break();

  3. #3
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Code:
    // open setting.ini in writing mode
    if ( (setPtr = fopen("setting.ini","r")) == NULL)
    :P
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  2. character jump
    By pode in forum Game Programming
    Replies: 7
    Last Post: 12-31-2002, 07:22 AM
  3. assembled Jump
    By Unregistered in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 12-14-2001, 10:10 AM
  4. next step in a jump
    By cheesehead in forum Linux Programming
    Replies: 0
    Last Post: 12-11-2001, 10:08 AM