Thread: Student Question3

  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    25

    Question Student Question3

    Ok Guy's,
    My instructor gave me this feedback: "Your totals are fine, but your taxes
    are off by a factor of 100. Your error checking is effective, but should
    terminate the program rather than continuing to show taxes on a $0 purchase.

    I honestly have no clue what to do. Any suggestions would be appreciated.

    Code:
    /*Kudler Fine Foods Tax calculator*/
    //Description: A C program by Max Maxwell that displays the sales tax amount for each of the store locations based on taxable
    //amounts entered by the user.
    
    #include<stdio.h>
    #include <stdlib.h>
    int main (void)
    
    {
    	//declaring variables 
    		float Purchase_Amount = 0.0; //Variable for the purchase amount initialized at 0
    		float DelMar_TaxRate = 7.25; //Del Mar Tax Rate
    		float Encinitas_TaxRate = 7.50; //Encinitas Tax Rate
    		float LaJolla_TaxRate = 7.75; //La Jolla Tax Rate
    	
    	//Welcome Screen
    		printf("Kudler Fine Foods Tax Calculation Program\n");
    		printf("\nPlease Enter Your Purchase Amount: ");
    		if(scanf_s("%f", &Purchase_Amount) !=1) //Error Check and Message
    		{
    			printf(" That was an Invalid Purchase Amount. Please try again. Example 99.99, enter Zero to exit\n");
    		}
    
    		//Calculations For each location//
    		//TotalAmount  = PurchaseAmount * DelMarTaxRate / 100.00 + PurchaseAmount
    		printf("\nThe Del Mar Tax Rate of 7.25%% adds $%2.2f", DelMar_TaxRate * Purchase_Amount);
    		printf(" for a \ntotal of ---------> $%.2f.\n", ((DelMar_TaxRate / 100) * Purchase_Amount) + Purchase_Amount);
    		printf("\nThe Encinitas Tax Rate of 7.50%% adds $%2.2f", Encinitas_TaxRate * Purchase_Amount);
    		printf(" for a \ntotal of ---------> $%.2f.\n", ((Encinitas_TaxRate / 100) * Purchase_Amount) + Purchase_Amount);
    		printf("\nThe La Jolla Tax Rate of 7.75%% adds $%2.2f", LaJolla_TaxRate * Purchase_Amount);
    		printf(" for a \ntotal of ---------> $%.2f.\n", ((LaJolla_TaxRate / 100) * Purchase_Amount) + Purchase_Amount);
    		printf("\n\n\tThank you and have a nice day!\n\n");
    		return 0;
    }

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Your tax should never be expressed as:

    tax rate * purchase amount, when in % format.

    Correct is tax rate in per cent format / 100. Percent *means* hundreths.

    Your scanf() if statement could be appended to inclucde "...&& purchase_amount > 0.00)

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak;818469Correct is tax rate in [B
    per cent format[/B] / 100. Percent *means* hundreths.
    There is no such thing as per cent...

    And it sounds to me, Nezmin2, like you have a problem with incorporating logic.
    Therefore, I suggest you make a flow chart first. Then translate it into code.

    And I can spot the problem directly, why can't you (it's not a syntactic error; it's a logic error)?
    Last edited by Elysia; 12-18-2008 at 03:45 AM.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User
    Join Date
    Dec 2008
    Posts
    25

    Question

    Ok, despite the fact that the word student has gone over certian responders heads, I have gone in and restructured my formulas. Now everything is calculating correctly. However, now I am having issues compiling because of the exit() function.

    Code:
    #include<stdio.h>
    #include <stdlib.h>
    int main (void)
    
    {
    	//declaring variables 
    		float Purchase_Amount = 0.0; //Variable for the purchase amount initialized at 0
    		float DelMar_TaxRate = 7.25; //Del Mar Tax Rate
    		float Encinitas_TaxRate = 7.50; //Encinitas Tax Rate
    		float LaJolla_TaxRate = 7.75; //La Jolla Tax Rate
    	
    	//Welcome Screen
    		printf("\t\t\tKudler Fine Foods Tax Calculation Program\n");
    		printf("\nPlease Enter Your Purchase Amount: ");
    		if(scanf("%f", &Purchase_Amount) !=1) //Error Check and Message
    		{
    			printf("\nThat was an Invalid Purchase Amount. Please try again. Example 99.99, enter Zero to exit\n");
    			exit();
    		}
    
    		//Calculations For each location//
    		//TotalAmount  = PurchaseAmount * DelMarTaxRate / 100.00 + PurchaseAmount
    		printf("\nThe Del Mar Tax Amount equals: $%.2f", Purchase_Amount * DelMar_TaxRate / 100);
    		printf("\nfor a \ntotal of ---------> $%.2f.\n", (Purchase_Amount * DelMar_TaxRate / 100) + Purchase_Amount);
    		printf("\nThe Encinitas Tax Amount equals: $%.2f", Purchase_Amount * Encinitas_TaxRate / 100);
    		printf("\nfor a \ntotal of ---------> $%.2f.\n", (Purchase_Amount * Encinitas_TaxRate / 100) + Purchase_Amount);
    		printf("\nThe La Jolla Tax Amount equals: $%.2f", Purchase_Amount * LaJolla_TaxRate / 100);
    		printf("\nfor a \ntotal of ---------> $%.2f.\n", (Purchase_Amount * LaJolla_TaxRate / 100) + Purchase_Amount);
    		printf("\n\n\tThank you and have a nice day!\n\n");
    		return 0;
    }

  5. #5
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    We realize that you're a student. That doesn't mean we don't expect you to be able to read.
    Code:
    temp.c:18: error: too few arguments to function `exit'
    If you can't figure out what's wrong here, and you don't know how to look up exit in the back of your book/in the man page/in Google's man page, then why do you think we can do anything for you?

  6. #6
    Registered User
    Join Date
    Dec 2008
    Posts
    25
    Quote Originally Posted by tabstop View Post
    We realize that you're a student. That doesn't mean we don't expect you to be able to read.
    Code:
    temp.c:18: error: too few arguments to function `exit'
    If you can't figure out what's wrong here, and you don't know how to look up exit in the back of your book/in the man page/in Google's man page, then why do you think we can do anything for you?
    WOW!!! Anyways... I am now using exit(0) and it now terminates the program.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Wow? Do you not get any error messages, or do you not see them?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Registered User
    Join Date
    Dec 2008
    Posts
    25

    Question

    Quote Originally Posted by Elysia View Post
    Wow? Do you not get any error messages, or do you not see them?
    Elysia,
    The only warnings that I am recieving is the Microsoft scanf_s () message which according to my instructor and some research that I did on the web is only for security purposes.

    Can you point out to me what you are seeing? As I have stated earlier, I am a student and I love constructive criticism, as long as it's respectful.

  9. #9
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Exit needs a value to what I understand, I never use it much.

    Code:
    exit(0);
    I think it is under stdlib.h
    Double Helix STL

  10. #10
    Registered User
    Join Date
    Dec 2008
    Posts
    25
    Quote Originally Posted by swgh View Post
    Exit needs a value to what I understand, I never use it much.

    Code:
    exit(0);
    I think it is under stdlib.h
    Thank you sw...

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Nezmin2 View Post
    Elysia,
    The only warnings that I am recieving is the Microsoft scanf_s () message which according to my instructor and some research that I did on the web is only for security purposes.

    Can you point out to me what you are seeing? As I have stated earlier, I am a student and I love constructive criticism, as long as it's respectful.
    It should spit out an error saying:
    Error: not enough arguments for function exit, or similar.

    The only time I can think it would not do that is if you call the function without using a proper prototype (ie, not included the required header), in which case it should give a waring about calling a function without a prototype.

    Perhaps the warning level is not high enough. If you go to projects, C/C++, General and set Warnings to level 4, do you get warnings then?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Updating in a sequential file?
    By Ronnyv1 in forum C Programming
    Replies: 1
    Last Post: 03-24-2009, 04:41 PM
  2. Student Question3
    By Nezmin2 in forum C Programming
    Replies: 2
    Last Post: 12-15-2008, 11:00 PM
  3. Database assignment is Killing me!
    By Boltrig in forum C Programming
    Replies: 2
    Last Post: 11-29-2007, 03:56 AM
  4. LinkList Sorting in C
    By simly01 in forum C Programming
    Replies: 3
    Last Post: 11-25-2002, 01:21 PM
  5. Creating a student grade book-how?
    By Hopelessly confused in forum C Programming
    Replies: 5
    Last Post: 10-03-2002, 08:43 PM