Can anybody check this?

This is a discussion on Can anybody check this? within the C Programming forums, part of the General Programming Boards category; The program runs fine and I have added validation checks. However, I'm trying to add a printf which will show ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    15

    Can anybody check this?

    The program runs fine and I have added validation checks.

    However, I'm trying to add a printf which will show up only when the data input is invalid and the field gets displayed again (just take a look at the first field (Dept No) for an example). So far, it hasn't worked as whatever I put as error message shows up whether the date is consistent or not.

    Code:
    /********************Income Tax Program***************************/
    
    /***********************HEADER FILES*****************************/
    #include<stdio.h>
    #include<string.h>
    #include<conio.h>
    #include<stdlib.h>
    #include<ctype.h>
    
    /********************LIBRARY FUNCTIONS**************************/
    void menu(void);           /*Menu*/
    void details(void);        /*Entry details*/
    void financial(void);      /*Financial details*/
    void report(void);         /*Final report*/
    void exit(void);            /*Exit program*/
    void printlogo(void);      /*ABC Ltd. header*/
    
    
    /*********************DECLARATION OF VARAIBLES******************/
    int i = 0;
    int length;
    int situation;
    char answer[1];
    char dept_no[3];
    char dept_name[15];
    char dept_leader_surname[60];
    char dept_leader_other[80];
    char tel_no[7];
    int fax[7];
    char other_means[1];
    float reg_inc, fringe, allocation, bonus;
    float wages, maintain, transactions, other_issues, emp_needs;
    float total_revenue, net_loss, benefit;
    
    
    /*****************************Main****************************/
    void main(void)
    {
        situation == true;
        printlogo();
    
                     /*Password protection*/
    
                    /*Password: neoteric*/
    
                    /*Encrypting password*/
    
       char encrypted[] = "EBuANANatYHcbQvIhAnU";
    
       char password[80];
       char unencrypted[] = "abcdefghijklmnopqrst";
    
       int i = 0;
       long code = 0;
    
       for(;;)
       {
       strcpy(unencrypted, "abcdefghijklmnopqrst");
       printf("\n\n\nEnter password (max. 20 characters, no spaces): ");
       scanf("%s", password);
    
       for( i= 0; i < 20 && password[i] != '\0'; i++)
       unencrypted[i] = password[i];
       code = 0;
    
       for(i=0; i < 20; code += unencrypted[i++]);
       code %= 52;
       code += code < 26 ? 'A' : ('a' - 26);
    
       for(i = 0; i < 20; i++)
       {
         code *= unencrypted[i];
         code %= 52;
         code += (code < 26) ? 'A': ('a' - 26);
    
         password[i] = (char)code;
       }
       password[i] = '\0';
    
                             /*Checking password*/
    
       if(strcmp(password, encrypted) != 0)
       printf("\nAccess denied!\n");
       else
         {
          clrscr();
          menu();
          break;
         }
    
       }
    
    }
    
    
    /*****************************Menu****************************/
    void menu(void)
    {
         printlogo();                 /*Calls function logo*/
    
         printf("\n\n\nPlease choose desired option:");
         printf("\n\n\t[1] Entry details.");
         printf("\n\n\t[2] Financial details.");
         printf("\n\n\t[3] Display final report.");
         printf("\n\n\t[4] Exit.");
    
         int choice;
         printf("\n\n\t");
         scanf("%d", &choice);
         switch(choice)            /*Determine chosen option*/
         {
           case 1:
           details();             /*Go to chosen option (function)*/
           break;
    
           case 2:
           financial();
           break;
    
           case 3:
           report();
           break;
    
           case 4:
           exit();
           break;
    
           default:
           printf("\n\nInvalid option. Please choose again.");
           flushall();
           getchar();
    
           }
    
    }
    
    
    /********************************Entry details******************************/
    void details(void)
    {
         clrscr();
    
         int result;
    
         printf("\n\n\n                          ENTRY DETAILS");
    
         do
         {
           result = 0;
           printf("\n\n\nDepartment number: ");
           scanf("%s", &dept_no);
           int length = strlen(dept_no);
           for(int i = 0; i < length; i++)
           {
             if(isalpha(dept_no[i]))
             result = 1;
           }
         }
         while(result == 1);
    
    
         do
         {
           result = 0;
           printf("\n\nFull department name: ");
           scanf("%s", &dept_name);
           int length = strlen(dept_name);
           for(int i = 0; i < length; i++)
           {
             if(isdigit(dept_name[i]))
             result = 1;
           }
         }
         while(result == 1);
    
    
         do
         {
           result = 0;
           printf("\n\nDepartment manager's surname (BLOCK LETTERS): ");
           scanf("%s", &dept_leader_surname);
           int length = strlen(dept_leader_surname);
           for(int i = 0; i < length; i++)
           {
             if(isdigit(dept_leader_surname[i]))
             result = 1;
           }
         }
         while(result == 1);
    
    
         do
         {
           result = 0;
           printf("\n\nDepartment manager's other names: ");
           scanf("%s", dept_leader_other);
           int length = strlen(dept_leader_other);
           for(int i = 0; i < length; i++)
           {
             if(isdigit(dept_leader_other[i]))
             result = 1;
           }
         }
         while(result == 1);
    
    
         do
         {
           result = 0;
           printf("\n\nTelephone number: ");
           scanf("%s", &tel_no);
           int length = strlen(tel_no);
           for(int i = 0; i < length; i++)
           {
             if(isalpha(tel_no[i]))
             result = 1;
           }
         }
         while(result == 1);
    
    
         printf("\n\nFax number: ");
         scanf("%d", &fax);
    
         clrscr();
    
         financial();
    
         getchar();
         getchar();
    
       }
    
    
    /******************************Financial details*****************************/
       void financial(void)
       {
         printf("\n\n\n                          FINANCIAL DETAILS");
    
                                    /*Income*/
         printf("\n\n\nNet regular income: Rs ");
         scanf("%f", &reg_inc);
    
         printf("\n\nDid department perceive any income"
                " through other means (Y/N)?: ");
         scanf("%s", other_means);
    
         if(strnicmp(other_means, "Y", 1) == 0)
         {
           printf("\n\nFringe benefits: Rs ");
           scanf("%f", &fringe);
           getchar();
         }
    
         printf("\n\nAmount allocated by management: Rs ");
         scanf("%f", &allocation);
    
         printf("\n\nBonus emoluments: Rs ");
         scanf("%f", &bonus);
    
                                /*Expenses*/
         printf("\n\nAmount spent as wages to employees: Rs ");
         scanf("%f", &wages);
    
         printf("\n\nAmount lost through transactions: Rs ");
         scanf("%s", &transactions);
    
         printf("\n\nAmount spent to cater for employees' other needs: Rs ");
         scanf("%f", &emp_needs);
    
         printf("\n\nAmount spent on maintenance and similar issues: Rs ");
         scanf("%f", &maintain);
    
         printf("\n\nAmount spent on any other issues: Rs ");
         scanf("%f", &other_issues);
    
         clrscr();
    
         report();
    
       }
    
    
    /********************************Final report*********************************/
       void report(void)
       {
         printf("\n\n\n                             REPORT");
    
                           /*Displaying entry details*/
         printf("\n\nDepartment number is %d", *dept_no);
    
         printf("\n\nDepartment name is %s", dept_name);
    
         printf("\n\nDepartment leader's full name is %s %s",
                    dept_leader_other, dept_leader_surname);
    
         printf("\n\nTelephone number: %d", *tel_no);
    
         printf("\n\nFax number: %d", *fax);
    
    
                       /*Performing income tax calculations*/
    
         /*Calculate total revenue*/
         total_revenue = reg_inc + fringe + allocation + bonus;
    
         /*Calculate net loss*/
         net_loss = wages + transactions + emp_needs + maintain + other_issues;
    
         /*Print total revenue*/
         printf("\n\nTotal revenues for department amount to Rs %0.2f", total_revenue);
    
         /*Display net loss*/
         printf("\n\nNet loss for department amounts to Rs %0.2f", net_loss);
    
         /*Calculate benefit*/
         benefit = total_revenue - net_loss;
    
                     /*Calculate tax (varies upon benefit)*/
         if(benefit <= 50000)
         printf("\n\nTax payable: Rs %0.2f", benefit*0.15);
    
         if(benefit > 50000)
         printf("\n\nTax payable: Rs %0.2f", benefit*0.25);
    
                    /*List of forms required when payment is made*/
         printf("\n\nPlease attach originals of the following forms:");
         printf("\nOriginals of income forms.");
         printf("\nOriginals of expense forms.");
    
                         /*Continue onto menu, or exit program*/
         printf("\n\n\nDo you wish to continue? (Y/N): ");
         scanf("%s",answer);
         if(strnicmp(answer, "Y", 1) == 0)
         {
           clrscr();
           menu();
         }
         else
           exit();
    
    }
    
    
    /*****************************Exit program******************************/
       void exit(void)
       {
           situation == false;
       }
    
    
    /*****************************ABC Ltd. Logo****************************/
     void printlogo(void)
    {
    
    
       printf("          -----------------------------------------------");
       printf("\n         |                                               |");
       printf("\n         |          ABC COMPANY LTD (MAURITIUS)          |");
       printf("\n         |                                               |");
       printf("\n         |              ANNUAL INCOME TAXES              |");
       printf("\n         |                                               |");
       printf("\n          -----------------------------------------------");
    }

  2. #2
    Registered User Sargnagel's Avatar
    Join Date
    Aug 2002
    Posts
    166
    The scanf() function is a source of errors! Read this:

    http://www.drpaulcarter.com/cs/common-c-errors.php#4.3

    I hope, this will help you.

  3. #3
    Registered User planet_abhi's Avatar
    Join Date
    Oct 2002
    Posts
    92

    Question

    Which compiler u used?
    AbHHinaay

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BN_CLICKED, change button style
    By bennyandthejets in forum Windows Programming
    Replies: 13
    Last Post: 07-06-2010, 12:42 AM
  2. how to check input is decimal or not?
    By kalamram in forum C Programming
    Replies: 3
    Last Post: 08-31-2007, 08:07 PM
  3. Please check this loop
    By Daesom in forum C++ Programming
    Replies: 13
    Last Post: 11-02-2006, 01:52 AM
  4. A way to check for Win98 or WinXP
    By Shadow in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-31-2002, 11:06 AM
  5. how to check for end of line in a text file
    By anooj123 in forum C++ Programming
    Replies: 6
    Last Post: 10-25-2002, 12:21 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21