Thread: Code Assistance

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

    Question Code Assistance

    Ok Guy's,

    Here is my code for a Tax Calculation program (beginning C Programming Concepts class). I am trying to figure out how to let the user input the location as well as the total taxable amount.
    Code:
    #include<stdio.h>
    
    int main (void)
    
    {
    	int tax_input;
    	tax_calculator();
    	return 0;
    } 
    
    int tax_calculator (void)
    
    {
    	// The total sales for each store is
    	float iOperand1=0.0;
    	//Display Program Header
    	printf ("\nKudler Fine Foods tax calculator\n");
    	//Calculate and print the Tax for Del Mar
    	printf ("\nEnter the total taxable amount of purchase at the Del Mar location: ");
    	scanf ("%f", &iOperand1);
    	printf ("The tax on the purchase at the Del Mar location is %.2f\n", iOperand1*.0725);
    	//Calculate and print the Tax for Encinitas
    	printf ("\nEnter the total taxable amount of purchase at the Encinitas location: ");
    	scanf ("%f", &iOperand1);
    	printf ("The tax on the purchase at the Encinitas location is %.2f\n", iOperand1*.075);
    	//Calculate and print the Tax for La Jolla
    	printf ("\nEnter the total taxable amount of purchase at the La Jolla location: ");
    	scanf ("%f", &iOperand1);
    	printf ("The tax on the purchase at the La Jolla location is %.2f\n", iOperand1*.0775);
    	getch();
    	return 0;
    }

    I know that this is not formatted correctly and I am sorry for that. I am still trying to figure out how to format code using MS VC++ Express.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by Nezmin2 View Post
    I am still trying to figure out how to format code using MS VC++ Express.
    I think there is a long bar called "space"; also on the keyboard is tab and enter. But you're formatting's not that bad anyway.

    By "input location", do you mean you want the user to enter a location first, and then the program will respond with one (but not all) of the "at location" lines above?
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    25
    Quote Originally Posted by MK27 View Post
    I think there is a long bar called "space"; also on the keyboard is tab and enter. But you're formatting's not that bad anyway.

    By "input location", do you mean you want the user to enter a location first, and then the program will respond with one (but not all) of the "at location" lines above?
    Thanks MK,
    Yes, I am wanting the user to select a location then input the total taxable amount.

  4. #4
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Well, you could present a menu corresponding to integers:

    1) Del Mar
    2) Encinitas
    3) La Jolla

    That will make it easier to apply the user's response in a switch/case block:
    Code:
    switch (location) {
         case 1: printf ("The tax on the purchase at the Del Mar location is %.2f\n", iOperand1*.0725);
                    break;
         case 2: printf ("The tax on the purchase at the Encinitas location is %.2f\n", iOperand1*.075);
                    break;
    
              ...etc.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    ps. you might want to look the "trying to convert a total amount into change" thread going on now for some caveats regarding money and floats in C if you are calculating a tax...

    http://cboard.cprogramming.com/showthread.php?t=110039
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

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

    Question

    Thanks MK,
    I will repost my code once I have made these fixes and fully understand what they do and how they do it.

    P.S. I am using MS VC++ Express as my compiler. This code builds fine and when I run the "Start without Debugging" action it executes perfectly. However, when I attempt to compile it I get a "Cannot open source file:" error. What I need is an executable to post for my class but I have no idea how to get it from this program. Any ideas?

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Since "build" == "compile", that makes no sense. How are you trying to compile it in a way different from building it?

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

    Question

    Quote Originally Posted by tabstop View Post
    Since "build" == "compile", that makes no sense. How are you trying to compile it in a way different from building it?
    Sorry Tab, this is my programming ignorance coming out. I was not aware that build==compile. What I need is an executable to turn in for my class. Would you by chance know how I would create that?

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    You already did. Since you're using MS VC++, you need to go into the debug folder of your project folder, and hey presto there it is.

  10. #10
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    build == compile when using the VC menu options.
    Technically build == compile+link but as there's no separate options for those in the VC GUI they're effectively the same as far as you're concerned unless you start using the commandline compiler and select specific options.

  11. #11
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    Quote Originally Posted by jwenting
    build == compile when using the VC menu options.
    Technically build == compile+link but as there's no separate options for those in the VC GUI they're effectively the same as far as you're concerned unless you start using the commandline compiler and select specific options.
    From my experience with Visual Studio 2005, "build" really does mean "compile and link", not just "compile". "Compile" is available by default from a drop down menu or a keyboard shortcut, and the GUI can be configured to add it to the toolbar as an icon option.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

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

    Thumbs up

    Quote Originally Posted by laserlight View Post
    From my experience with Visual Studio 2005, "build" really does mean "compile and link", not just "compile". "Compile" is available by default from a drop down menu or a keyboard shortcut, and the GUI can be configured to add it to the toolbar as an icon option.
    Thank you very much Laserlight!!!

  13. #13
    chococoder
    Join Date
    Nov 2004
    Posts
    515
    Quote Originally Posted by laserlight View Post
    From my experience with Visual Studio 2005, "build" really does mean "compile and link", not just "compile". "Compile" is available by default from a drop down menu or a keyboard shortcut, and the GUI can be configured to add it to the toolbar as an icon option.
    That's what I meant, that there are no separate compile and link options in the VC menu
    Could possibly have stated it a bit less ambiguously.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 07:34 AM
  2. Values changing without reason?
    By subtled in forum C Programming
    Replies: 2
    Last Post: 04-19-2007, 10:20 AM
  3. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 05:06 PM
  4. C code assistance please
    By lotus in forum C Programming
    Replies: 7
    Last Post: 05-25-2002, 02:29 AM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM