Thread: Application program- help!

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    47

    Unhappy Application program- help!

    Can someone please look at the below code and tell me what my first mistake is. I have enclosed in braces and still keep getting error messages.

    #include <stdio.h> /* Include header to allow use of console functions */
    #include <stdlib.h> /* Include header to allow use of system functions */

    #define ADULT 18 /* Age breakpoint for an adult */
    #define SMWD 1,000 /* Salary multiplier with degree */
    #define SMWO 600 /* Salary multiplier without degree */

    int main (void)
    {
    float AGE, /* Applicant's age */
    WHN; /* When to apply again in years */
    char DEG; /* College degree status (Y/N) */
    double SAL; /* Annual salary offer */

    system ("cls"); /* Clear the Screen */
    printf ("Applicant Screening Program\n\n");
    printf ("How old are you?");
    scanf ("%f", & AGE);


    if (AGE >= ADULT)
    {
    printf ("Do you have a college degree (Y/N)?\n"); scanf ("%c", & DEG);
    }
    else { printf ("\nSorry, you must be %d or older for this job.\n", ADULT;
    printf ("Please apply again in %d years.\n", WHN);

    }

    if (DEG == 'Y' || 'y') SAL = AGE * SMWD;
    else SAL = AGE * SMWO;
    }

    printf ("You qualify!\n");
    printf ("Your annual salary would be $%8.2f.\n", SAL);
    printf ("See our staff for an application.\n");

    return (0); /* Send a null error code to the parent process */
    }

  2. #2
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,834
    Don't put commas in number: #define SMWD 1,000
    if (DEG == 'Y' || 'y') should be if (DEG == 'Y' || DEG == 'y')

  3. #3
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,534
    Code:
    printf ("\nSorry, you must be %d or older for this job.\n", ADULT;
    You have to match the parentheses.

    Code:
    else SAL = AGE * SMWO;
    }
    You have one brace too many.

    That should get rid of your immediate trouble, but you have a lot of work to do yet.

    Also, you should learn to use code tags if you are posting on forums. Nobody wants to look at a bunch of code without indentation...

    Code:
    #include <stdio.h>              /* Include header to allow use of console functions */
    #include <stdlib.h>             /* Include header to allow use of system functions */ 
    
    #define ADULT 18                /* Age breakpoint for an adult */
    #define SMWD 1,000              /* Salary multiplier with degree */
    #define SMWO 600                /* Salary multiplier without degree */
    
    int main(void)
    {             
        float AGE,                  /* Applicant's age */
         WHN;                       /* When to apply again in years */
        char DEG;                   /* College degree status (Y/N) */ 
        double SAL;                 /* Annual salary offer */         
    
        system("cls");              /* Clear the Screen */
        printf("Applicant Screening Program\n\n");        
        printf("How old are you?");                       
        scanf("%f", &AGE);
    
    
        if (AGE >= ADULT) {
            printf("Do you have a college degree (Y/N)?\n");
            scanf("%c", &DEG);
        } else {
            printf("\nSorry, you must be %d or older for this job.\n", ADULT);
            printf("Please apply again in %d years.\n", WHN);
    
        }
    
        if (DEG == 'Y' || 'y')
            SAL = AGE * SMWD;
        else
            SAL = AGE * SMWO;
    
    
        printf("You qualify!\n");
        printf("Your annual salary would be $%8.2f.\n", SAL);
        printf("See our staff for an application.\n");
    
        return (0);                 /* Send a null error code to the parent process */
    }
    Last edited by kermit; 09-29-2009 at 03:25 PM.

  4. #4
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    Quote Originally Posted by kburyanek View Post
    I [..] still keep getting error messages.
    you will get help faster if you tell us what your error messages are, rather than expecting us to manually debug your code (howerver long or short it may be), find out what you want it to do and find out what it is doing.

    so tell us exactly what the "error message" is at least. also surround your code by "CODE" tags to keep its formatting (assuming it was formatted/indented nicely) so its even easier for us to read and follow. of course: if you make it hard for us ==> we make it hard for you.

    EDIT: it appears we're doing the work for you, so:
    - "system("cls")" makes your program windows-specific and not fully portable (maybe your not concerned with that, but portability is very often a good thing)
    - you never initialized "WHN" but your using it
    - your not taking into account the newlines being left in buffer by scanf
    Last edited by nadroj; 09-29-2009 at 03:26 PM.

  5. #5
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    Thank you, I really appreciate this.

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    Thank you, I am just still learning. I appreciate the help.

  7. #7
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    Here are the error messages. I have been following the examples that my instructor has given me and he wants you to clear the screen.

    For some reason I can not get my error messages copied to another file so that I may show them.

    Thank you

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    No, he wants you to clear the screen. He doesn't want anything from me.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    I do not think so, in his example to use he has shown that this should be put in the code. We are following a Flowchart and are suppose to follow to the exact chart in regards to clear the screen. I have adjusted my code and have only about 5 errors. Hopefully I will get them worked out. I read everything here and then he wants us to do something different, it is confusing.

    Code:
    /*****************************************************
    * Program:  apply.c - Project 5 - Coding Selection   *
    *****************************************************/
    
    
    #include <stdio.h>    /* Include header to allow use of console functions */
    #include <stdlib.h>   /* Include header to allow use of system functions */
    
    #define ADULT 18     /* Age breakpoint for an adult */
    #define SMWD 1000   /* Salary multiplier with degree */
    #define SMWO 600     /* Salary multiplier without degree */
    
    int main (void)
    {
    	float  AGE,     /* Applicant's age */
    	       WHN;     /* When to apply again in years */
    	char   DEG;     /* College degree status (Y/N) */
    	double SAL;     /* Annual salary offer */
    
    system ("cls");     /* Clear the Screen */
    printf ("Applicant Screening Program\n\n");
    printf ("How old are you?");
    scanf ("%f", & AGE);
    
    
    if (AGE >= ADULT){
    	printf ("Do you have a college degree (Y/N)?\n");
        scanf ("%c", & DEG);
    }
    else { printf ("\nSorry, you must be %d or older for this job.\n", ADULT);
    
    WHN = ADULT - AGE;
    
    	printf ("Please apply again in %d years.\n", WHN); scanf ("%1f, & WHN);
    }
    if
    	SAL = AGE * SMWD;
    else
    	SAL = AGE * SMWO;
    }
    
    printf ("You qualify!\n");
    printf ("Your annual salary would be $%8.2f.\n", SAL);
    printf ("See our staff for an application.\n");
    
    return (0);   /* Send a null error code to the parent process */
    }

  10. #10
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    any "instructor" that cares about primitive aesthetics such as clearing the screen, in an introduction programming course, is a pretty bad sign, in my opinion. especially forcing you do write non-portable code.

    you said you still have errors, are you able to post them? if you get complaints from CBoard when adding a post, it might be because its forcing you to surround the text with CODE tags.

  11. #11
    Registered User
    Join Date
    Sep 2009
    Posts
    47
    line 34- Unterminated string or char const

    line 34 - printf argument mismatch for format d. Expected int got double. (I tried changing this to %f and still error).

    line 35-illegal expression

    Line 36
    syntax error; found 'f' expecting 'j'
    missing semicolon before if

    line 37
    found 'SAL' expecting '('
    found ; expecting ')'

  12. #12
    Make Fortran great again
    Join Date
    Sep 2009
    Posts
    1,413
    printf ("Please apply again in %d years.\n", WHN)

    WHN is a float, not an integer

    immediately after that, you're missing the if conditional

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BOOKKEEPING PROGRAM, need help!
    By yabud in forum C Programming
    Replies: 3
    Last Post: 11-16-2006, 11:17 PM
  2. Can someome help me with a program please?
    By WinterInChicago in forum C++ Programming
    Replies: 3
    Last Post: 09-21-2006, 10:58 PM
  3. Launching an application from my program
    By tao in forum Windows Programming
    Replies: 6
    Last Post: 07-04-2006, 01:15 PM
  4. I need some help with my program please.
    By agentxx04 in forum C Programming
    Replies: 9
    Last Post: 09-26-2004, 07:51 AM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM