Question?

This is a discussion on Question? within the C Programming forums, part of the General Programming Boards category; I prepared an if statement which asked the following info in this order: employee name, amount of sale, commission type, ...

  1. #1
    Unregistered
    Guest

    Question Question?

    I prepared an if statement which asked the following info in this order:

    employee name, amount of sale, commission type, and then went on to display total commission and total sales as well as employee of the month.

    When I went to run it, it asked for the employee name but displayed the rest which followed without prompting me for any of the other entries for which I used a printf and a scanf.

    Does anyone know if there is something more I need to do with "char" for the employee name in my declaration?

    Help?

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    Post your code so we can see what your doing.
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Unregistered
    Guest
    Starting to get discouraged with my beginner's programming skills: help>>>>
    --------------------------------------------------------------------------------

    #include <stdio.h>

    #define S_COMMISSION 4.0
    #define R_COMMISSION 6.5

    main()
    {
    char salesperson_name [50], /* displays salesperson's name */
    type, /* type of commission */
    response;
    float sales, /* displays sales */
    total, /* keeps track of company total */
    total_sales, /* keeps track of total sales */
    total_commission; /* keeps track of total for commission */
    int salesperson_count;

    salesperson_count = 0;
    sales = 0.00;
    total = 0.00;
    total_sales = 0.00;
    total_commission = 0.00;

    /*Obtain input */

    printf("\nPlease enter Salesperson Name: ");
    scanf("%c", &response);

    printf("\nPlease enter Type code: ");
    scanf("%c", &type);
    printf("\nPlease enter Sales: ");
    printf("\nPlease enter Sales: ");
    scanf("%d", &sales);

    printf("\nCommission for %c is: %d\n");

    * If Statement */

    if (type == S_COMMISSION)
    {
    total_sales += sales;
    printf("\nTotal Sales for Type S:", total_sales);
    total_commission = S_COMMISSION * sales;
    printf("\nTotal Commission for Type S:", total_commission);
    }
    if (type == R_COMMISSION)
    {
    total_sales += sales;
    printf("\nTotal Sales Type R:", total_sales);
    total_commission = R_COMMISSION * sales;
    printf("\nTotal Commission for Type R:", total_commission);
    }
    else
    {
    total_sales += sales;
    printf("\nTotal Sales for Company: \n\n");
    total_commission += total_commission;
    printf("\nTotal Commission for Company: \n\n");
    printf("\nSalesperson of the Month is: %c \n\n");
    }
    }

  4. #4
    Unregistered
    Guest

    Red face Take a look....

    Can someone take a look....I re-wrote some parts.

    #include <stdio.h>

    #define S_COMMISSION 4.0
    #define R_COMMISSION 6.5

    main()
    {
    char salesperson_name [50];
    float sales,total,total_sales,total_commission; int type;

    salesperson_count = 0;
    sales = 0.00;
    total = 0.00;
    total_sales = 0.00;
    total_commission = 0.00;

    /*Obtain input */

    printf("\nPlease enter Salesperson Name: ");
    gets(salesperson_name);
    printf("\nPlease enter Type code: ");
    scanf("%d", &type);
    printf("\nPlease enter Sales: ");
    scanf("%d", &sales);
    printf("\nCommission for %c is: %d\n");

    /* If Statement */

    if (type == 'S')
    {
    total_sales += sales;
    total_commission = S_COMMISSION * sales;
    printf("\nTotal Sales for Type S:", total_sales);
    printf("\nTotal Commission for Type S:", total_commission);
    }
    if (type == 'R')
    {
    total_sales += sales;
    total_commission = R_COMMISSION * sales;
    printf("\nTotal Sales Type R:", total_sales);
    printf("\nTotal Commission for Type R:", total_commission);
    }

    total_sales += sales;
    total_commission += total_commission;
    printf("\nTotal Sales for Company: \n\n");
    printf("\nTotal Commission for Company: \n\n");

    if (total_commission >=100)
    printf("\nSalesperson of the Month is: %c \n\n");
    }

  5. #5
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    salesperson_count = 0;
    You haven't declared saleperson_count.
    scanf("%d", &sales);
    sales is a float so you need %f not %d.
    printf("\nCommission for %c is: %d\n");
    You use %c and %d in the printf but give it no arguments.
    printf("\nTotal Sales for Type S:", total_sales);
    printf("\nTotal Commission for Type S:", total_commission);
    printf("\nTotal Sales Type R:", total_sales);
    printf("\nTotal Commission for Type R:", total_commission);
    in all these printfs you need to use %f to display the argument.

    printf("\nTotal Sales for Company: \n\n");
    printf("\nTotal Commission for Company: \n\n");
    These 2 printfs aren't wrong but they print headings for totals you dont give???
    printf("\nSalesperson of the Month is: %c \n\n");
    again you have a %c but no corresponding argument as this is meant to print a string however you should use %s.

    Read up on the printf function and format specifiers
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  6. #6
    Unregistered
    Guest

    Cool Thanks

    Thank you C_Coder!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Alice....
    By Lurker in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 06-20-2005, 03:51 PM
  2. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 06:51 PM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 01:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

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