simple tax program

This is a discussion on simple tax program within the C Programming forums, part of the General Programming Boards category; Pretty simple program. The program runs fine. Do you think the program is acceptable considering the parameters set by the ...

  1. #1
    Registered User CASHOUT's Avatar
    Join Date
    Jul 2011
    Location
    Florida
    Posts
    88

    simple tax program

    Pretty simple program.
    The program runs fine.
    Do you think the program is acceptable considering the parameters set by the instructions?

    Create a small program based on the following

    // encourage the use of user-defined functions
    // (calculates different sales tax based on an item price)

    1. Ask the user to enter the price of an item.
    2. Get the item price from the user.
    3. Calculate the sales tax of the item:
    - 7% if the item costs less than $200.
    - 5% if the item costs $200 or more.
    4. Display the original item price and sales tax amount onto the screen.
    5. Calculate new cost of the item with the sales tax.
    6. Display the total price of the item onto the screen.




    Code:
    #include<stdio.h>
    #include<math.h>
    
    
    double getPrice(void);
    
    int main(void){
    	
    	double price = 0.0;	
    	double sevenP = 0.0;
    	double fiveP = 0.0;
    
    	printf("PLease enter the price of the customers purchase:\t$");
    		price = getPrice();
    	printf("The price is:\t $ %.2lf\n", price);
    	
    		sevenP = price * .07;
    		fiveP = price * .05;
    	
    		if (price < 200){
    	printf("The federal tax is: $ %.2lf\n", sevenP);
    	printf("The price plus the federal tax is: $ %.2lf\n", sevenP + price);
    		}else{
    	printf("The state tax is: $ %.2lf\n", fiveP);
    	printf("The price plus the state tax is: $ %.2lf\n", fiveP + price);
    		}
    	return 0;
    }
    double getPrice(void){
    
    	int value = 0;
    		scanf_s(" %d", &value);
    		return value;
    }

  2. #2
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,501
    When I did programming at Uni, we lost marks for poor indentation

    Choose one of these and stick to it Indent style - Wikipedia, the free encyclopedia

    You appear to be learning 1TBS - Just make sure your code only indents when you use a curly brace.

    Also, I would only calculate sevenP if the input was below 200 and vice versa.
    Fact - Beethoven wrote his first symphony in C

  3. #3
    Registered User
    Join Date
    Dec 2012
    Posts
    289
    i tend to use GNU, but instead of spaces, i use tab

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    2,706
    Code:
        double price = 0.0; 
    
        // ...
     
        printf("PLease enter the price of the customers purchase:\t$");
            price = getPrice();
    Getting the price (as a double), fine.

    Code:
    double getPrice(void);
    This function gets and returns a price (as a double). Fine.

    Code:
    double getPrice(void){
     
        int value = 0;
            scanf_s(" %d", &value);
            return value;
    }
    ... So why are you reading the value into an int and returning that?

    --------

    Oh, and you might want to consider following the rules of orthography (i.e. "Please" instead of "PLease").

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,855
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple program, simple problem
    By KAUFMANN in forum C Programming
    Replies: 5
    Last Post: 02-16-2011, 01:16 PM
  2. simple program, simple error? HELP!
    By colonelhogan44 in forum C Programming
    Replies: 4
    Last Post: 03-21-2009, 12:21 PM
  3. Simple program...simple problem?
    By deadherorising in forum C Programming
    Replies: 2
    Last Post: 03-12-2009, 09:37 PM
  4. Simple program, not so simple problem
    By nolsen in forum C++ Programming
    Replies: 2
    Last Post: 01-18-2008, 10:28 AM
  5. Need help with simple, simple program.
    By LightsOut06 in forum C Programming
    Replies: 5
    Last Post: 09-01-2005, 09:31 PM

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