Thread: Can not find my mistake in this code?

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

    Can not find my mistake in this code?

    I need to write this code and the problem I am having is it is not giving me the correct total. I can not pinpoint where my mistake is and was wondering if someone can help me with this? Here is the question from my homework (My work is at the bottom):

    Here is the information your program will ask the user to enter:
    1. The number of lower bowl tickets he/she wants to buy.
    2. The number of upper bowl tickets he/she wants to buy.
    3. The number of games worth of tickets he/she wants to buy.
    4. The sales tax in the locale in which the tickets are being bought, as a percentage.

    Prompt the user to input these four values. You will output a single statement with the total cost of the football tickets.

    Please define the following constants in your code:
    #define LOWER_BOWL_TIX_PRICE 50.00
    #define UPPER_BOWL_TIX_PRICE 25.00

    Input Specification
    1. The number of lower and upper bowl tickets will be integers in between 0 and 100, inclusive.
    2. The number of games the user will be buying tickets for will be in between 0 and 7, inclusive.
    3. The sales tax will be a real number percentage in between 0% and 20%

    Sample Run
    How many lower bowl seats do you want?
    2
    How many upper bowl seats do you want?
    4
    For many games do you want to buy these tickets?
    5
    What is the sales tax percentage in your locale?
    6.5
    The total cost of your football tickets is $1065.00.
    __________________________________________________ _____________________

    (MY WORK)



    Code:
    #include <stdio.h>
    #define LOWER_BOWL_TIX_PRICE 50.00
    #define UPPER_BOWL_TIX_PRICE 25.00
    
    int main(void)
    {
        int lower, upper, games;
        float sales_tax, tax, total, totala, totalb;
        
        printf ("How many lower bowl seats do you want? \n");
        scanf ("%d", &lower );
        if (lower<0 || lower>100)
           {
                  printf ("Invalid. Try Again. \n");
                  scanf ("%d", &lower );
                  }
        
        printf ("How many upper bowl seats do you want? \n");
        scanf ("%d", &upper );
        if (upper<0 || upper>100)
           {
                  printf ("Invalid. Try Again. \n");
                  scanf ("%d", &upper );
                  }          
                  
        printf ("For how many games do you want to buy these tickets? \n");
        scanf ("%d", &games );
        if (games<0 || games>7)
           {
                  printf ("Invalid. Try Again. \n");
                  scanf ("%d", &games );
                  }
                  
        printf ("What is the sales tax percentage in your locale? \n");
        scanf ("%f", &tax );
        if (tax<0 || tax>20)
           {
                  printf ("Invalid. Try Again. \n");
                  scanf ("%d", &tax );
                  }
                  
        sales_tax = tax/100;
        totala = (lower*50*games);
        totalb = (upper*25*games);
        total = (totala+totalb)* sales_tax;
        printf ("The total cost of your football tickets? \n");
        
        printf ("$%.2f", total );
    
        getch ();
        return 0;
        }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You're just printing the tax, not the total plus the tax.

  3. #3
    Registered User
    Join Date
    Sep 2009
    Posts
    14
    Quote Originally Posted by tabstop View Post
    You're just printing the tax, not the total plus the tax.
    I see. Thank you for that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Please help! - Who find mistake in the program??
    By nivek in forum C++ Programming
    Replies: 4
    Last Post: 01-06-2008, 01:28 AM
  2. Where to find the code that defines standard Functions?
    By hammer1234 in forum C Programming
    Replies: 7
    Last Post: 04-21-2006, 02:37 AM
  3. Replies: 6
    Last Post: 09-07-2004, 11:06 PM
  4. Code to find the day type of day in the year?
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 04-01-2002, 08:58 PM
  5. << !! Posting Code? Read this First !! >>
    By biosx in forum C++ Programming
    Replies: 1
    Last Post: 03-20-2002, 12:51 PM