Thread: I need HELP

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    Angry I need HELP

    I know that all of you are tired of hearing of so many of us working on code for class.

    I have got everything coded, but it is not working. I am using 'C', and using Mirace C and the editor.

    Below is the code if someone would like to help me.

    Code:
    /* Kudler Food Tax Calculator */
    //by Deborah Merry
    //Calcaulate Sales Tax
    //Class: POS370
    //Date: July 2007
    
    
    #include <stdio.h>
    
    
    main(void)
    {
    
    
    //Declare Variables
    float	fsubtotal, taxdelmar, taxencinitas, taxlajolla;
    float fCost;//calculation operator
    fCost = 0;
    
    fsubtotal=125.00;
    
    //variables
    /*Taxtotal=Subtotal*Taxrate*/
    taxdelmar=.0725;
    taxencinitas=.0775;
    taxlajolla=.0750;
    
    
    
    //Program Header
    printf("\n\tKudler Fine Foods 'Sales Tax Calculator'\n"); 
    
    
    
    
    {//start
    int iResponse = 0;
    	
    	/* clear the input buffer */
    	while((iResponse = getchar()) != '\n' && iResponse != EOF); 
    }
    
    {	
    		
    	printf("\n Welcome Del Mar Associate.\n");
    	printf(" Please enter your sub-total: $");
    	scanf("\n&#37;f", &fCost);//sale sub-total
    	printf(" --------------------------------\n");
    	printf(" Your total tax is $%.2f\n", fCost * .0725);//in-line calculation
    	printf(" The total amount owed is $%.2f\n", fCost * (1+.0725));//in-line calculation
    	break;
    	getchar();
    
    }
    {	
    	printf("\n Welcome Encinitas associate.\n");
    	printf(" Please enter your sub-total: $");
    	scanf("%f", &fCost);//sale sub-total
    	printf(" --------------------------------\n");
    	printf(" Your total tax is $%.2f\n", fCost * .075);//in-line calculation
    	printf(" The total amount owed is $%.2f\n", fCost * (1+.075));//in-line calculation
    	break;
    	getchar();
    }
    {
    	
    	printf("\n Welcome La Jolla associate.\n");
    	printf(" Please enter your sub-total: $");
    	scanf("%f", &fCost);//sale sub-total
    	printf(" --------------------------------\n"); 
    	printf(" Your total tax is $%.2f\n", fCost * .0775);//in-line calculation
    	printf(" The total amount owed is $%.2f\n", fCost * (1+.0775));//in-line calculation
    	break;
    	getchar();
    }
     	// end calc 
    
    getchar();//keeps application viewable on screen
    // end selection
    
    }
    Last edited by startingover; 07-30-2007 at 10:47 PM. Reason: left something out

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    you put return 0; at the end
    but it is not working.
    how?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Location
    Canada
    Posts
    1,243
    i doubt anyone, including myself, will look through your code, decide what it does, then decide where the problem lies, and then finally give you the answer.

    tell us what your program does, or at least what specifically 'is not working'. give us any ideas why you think it may not be working or other methods you have tried to solve the problem.

  4. #4
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    The most important part of your post was left out. Try telling us what the program is supposed to do. Then tell us what it is actually doing.

    Edit: Man, beat by two others. I must be getting old.

  5. #5
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    Not working

    Sorry everyone, I was in a hurry and did not take the time to think.

    I actually have the code working like it should, we are just required now to validate the user's input.

    Since I am tired, I am not putting the correct statement syntax in, for it to work correctly

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I am using 'C', and using Mirace C and the editor.
    The first thing to do is get a real compiler, not some nagware which fell out of a cereal packet as a 'free' gift.
    Miracle 'C' is utterly useless as a modern compiler. It fails in such bizarre ways on even the simplest of programs.

    Try something like dev-c++.
    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.

  7. #7
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    MacGyver, I apologize in asking for help with my "Homework". I decided late in life to start getting my degree, after I had my divorce and right now, I am just tired. Hopefully I will not have to bother anyone again.

    The way I see it, it is better late than never to get a degree and to obtain knowledge. Again I do apologize in asking for any assistance.

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    9
    Salem,

    Thanks, this was what the school had us download, I do have the Dev-c++ and I like it better because you can actually read where the error is, not that this helps fix, but it does help the whole process......

  9. #9
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by startingover View Post
    I actually have the code working like it should, we are just required now to validate the user's input.
    check the return value of scanf.

    http://cppreference.com/stdio/scanf.html

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You seem to have lots of braces, yet no program 'logic' which would make use of them.

    Are you supposed to be adding some kind of menu system, then making some choices to run the various bits of the code?

    > this was what the school had us download,
    I'm shocked.
    If whoever is teaching doesn't realise this is a broken compiler, I fear you won't learn much from them.
    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.

  11. #11
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    Wink Thank you

    I had actually written my code, I was just trying to really get some expert opinions on if I had done things correctly. I really like do things on my own, but always take into consideration those who are more experienced than I am.

    Thank you all for your enormous help and assistance. I know that I am on own, as it should be.

  12. #12
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    MacGyver, I apologize in asking for help with my "Homework". I decided late in life to start getting my degree, after I had my divorce and right now, I am just tired. Hopefully I will not have to bother anyone again.
    Dont worry about that. Its his signature. Its not specifically directed at you.

    in your code:
    Code:
    main(void)
    Should really be:
    Code:
    int main(void)
    Also I'm not sure if theres a reason for it, I don't know all that much about C, but you seem to have a lot of unnecessary opening/closing braces in your code.

  13. #13
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Quote Originally Posted by mike_g View Post
    Dont worry about that. Its his signature. Its not specifically directed at you.
    Indeed, it's just a signature meant for those that ask us to do their homework for them, not asking for help. It's attached to all of my posts, since that's how forum signatures work.

    I had absolutely no problem with this topic whatsoever except for what I explicitly stated: I felt the description of the problem was lacking, and therefore, it would be best to ask what the problem was instead of guessing. It was not a statement against the topic starter.

  14. #14
    Registered User
    Join Date
    Jul 2007
    Posts
    9

    My Work

    I definitely do not want anyone to do my homework for me, I do not learn that way. If I cannot learn, then there is no point in going to school in the first place. I guess that I thought that an expert, more than I am could look at what I did and guide me in the right direction to see what I have done and why it would not excute correcly.

    I have 3 locations, so the user needs to input their location and the amount of the sale and then it would come up with the tax and add it to the total.

    I could not get my closing correct for some reason and it is probably because I have everything too spread out. I need to clean it up some and it may work just fine. I hope so.

  15. #15
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    Looking at you code it as if you were trying to do a conditional check. Does this do what you want?
    Code:
    #include <stdio.h>
    
    int main(void)
    {
        //Declare Variables
        float fsubtotal, taxdelmar, taxencinitas, taxlajolla;
        float fCost;//calculation operator
        int iResponse = 0;
        
        fCost = 0;
        fsubtotal=125.00;
        taxdelmar=.0725;
        taxencinitas=.0775;
        taxlajolla=.0750;
    
        //Program Header
        printf("\n\tKudler Fine Foods 'Sales Tax Calculator'\n"); 
        printf("Chose a number between 1 and 3\n"); 
        
        //Repeatedly get input until a number between 1 and 3 is entered
        while(iResponse <= 0 || iResponse > 3) 
            scanf("%i", &iResponse);
        
        if(iResponse ==1)	
        {
    	    printf("\n Welcome Del Mar Associate.\n");
    	    printf(" Please enter your sub-total: $");
    	    scanf("\n%f", &fCost);//sale sub-total
    	    printf(" --------------------------------\n");
    	    printf(" Your total tax is $%.2f\n", fCost * .0725);//in-line calculation
    	    printf(" The total amount owed is $%.2f\n", fCost * (1+.0725));//in-line calculation
        }
        else if(iResponse ==2)	
        {
    	    printf("\n Welcome Encinitas associate.\n");
    	    printf(" Please enter your sub-total: $");
    	    scanf("%f", &fCost);//sale sub-total
    	    printf(" --------------------------------\n");
    	    printf(" Your total tax is $%.2f\n", fCost * .075);//in-line calculation
    	    printf(" The total amount owed is $%.2f\n", fCost * (1+.075));//in-line calculation
        }
        else
        {	
    	    printf("\n Welcome La Jolla associate.\n");
    	    printf(" Please enter your sub-total: $");
    	    scanf("%f", &fCost);//sale sub-total
    	    printf(" --------------------------------\n"); 
    	    printf(" Your total tax is $%.2f\n", fCost * .0775);//in-line calculation
    	    printf(" The total amount owed is $%.2f\n", fCost * (1+.0775));//in-line calculation
        }
        getchar();
        getchar();//keeps application viewable on screen
        // end selection
        return 0;
    }
    It would kind of explain all the unnecessary braces and breaks in your program.

Popular pages Recent additions subscribe to a feed