Totally lost beginner

This is a discussion on Totally lost beginner within the C Programming forums, part of the General Programming Boards category; I'm taking a C class at the local community college,but missed four classes due to surgery.I've been trying to catch ...

  1. #1
    Registered User
    Join Date
    Mar 2004
    Posts
    1

    Totally lost beginner

    I'm taking a C class at the local community college,but missed four classes due to surgery.I've been trying to catch up and a tutor won't be available until late next week.I have a lab assignment due Tuesday and I'm stuck.
    I have to create a program that calculates taxes owed depending on your tax bracket.I've managed to create a menu that will switch you to your tax bracket but don't understand how to get the user input to calculate.I don't know how to start.Please help!!The first tax bracket which is "single" uses the following calculation 0.15 * 17,850 + 0.28*(20000 - 17850)
    Below is the code I have written so far.If somone can give me some guidance it would be appreciated.

    Code:
    #include<stdio.h>
    char get_choice(void);
    int main(void)
    	{
    	  char ch ='e';
    
    	  while ( (ch < 'a' || ch > 'd') && ch != 'q')
    	  {
    
    						  printf("By entering your filing status from the menu below and then your annual income\n");
    						  printf("when prompted,this program will calculate your taxes owed.\n\n\n\n");
    						  printf("Enter the letter of your choice:\n\n");
    						  printf("a. Single\n");
    						  printf("b. Head of Household\n");
    						  printf("c. Married filing Jointly\n");
    						  printf("d. Married filing Seperately\n");
    						  printf("q. Exit Program\n");
    						  printf("Please respond with a, b, c, d or q.\n\n");
    
    						  ch = getchar();
    
    	  switch(ch)
    		  {
    						  case 'a' : printf("Please enter your taxable income: \n");
    										 break;
    						  case 'b' : printf("Please enter your taxable income: \n");
    										 break;
    						  case 'c' : printf("Please enter your taxable income: \n");
    										 break;
    						  case 'd' : printf("Please enter your taxable income: \n");
    										 break;
    						  default  : printf("Invalid entry\n\n");
    										 break;
    
    		  }
    	  }
    	  return 0;
    }

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    Hint:
    Code:
    double income;
    ...
    scanf ( "%lf", &income );
    Do you have a textbook to refer to?
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2004
    Posts
    18

    Are you in my class

    That sounds like something I did not too long ago in MY c. Let me check my notes. I too am stuck on something.

  4. #4
    Registered User
    Join Date
    Mar 2004
    Posts
    18

    In reference to the post above... a couple more hints

    you need to declare a variable for income(as mentioned above):
    Code:
     double income;
    then you have to scan it in
    Code:
    scanf("%lf", &income)
    I *think* you will have to do an if statement depending on how much money is in the "income" variable and then do a calculation based on that.
    Code:
     if(income <= 20000)
        "math here"
    so it should look something like this:
    Code:
     case 'a' : printf("Please enter your taxable income: \n");                     
                scanf("%lf", &income)
                if(income <= 20000)
                ---math here---
     case 'b' :  ---etc---
    and then do the math for each different tax bracket inside each of the cases. Is that helpful? You can also print out the results inside the cases as well.

  5. #5
    ... kermit's Avatar
    Join Date
    Jan 2003
    Posts
    1,528
    Code:
    #include<stdio.h>
    char get_choice(void);
    int main(void)
    	{
    	  char ch ='e';
    
    	  while ( (ch < 'a' || ch > 'd') && ch != 'q')
    	  {
    
    						  printf("By entering your filing status from the menu below and then your annual income\n");
    						  printf("when prompted,this program will calculate your taxes owed.\n\n\n\n");
    						  printf("Enter the letter of your choice:\n\n");
    						  printf("a. Single\n");
    						  printf("b. Head of Household\n");
    						  printf("c. Married filing Jointly\n");
    						  printf("d. Married filing Seperately\n");
    						  printf("q. Exit Program\n");
    						  printf("Please respond with a, b, c, d or q.\n\n");
    
    						  ch = getchar();
    
    	  switch(ch)
    I realise this has not much to do with the original question, however it is worth noting that getchar() returns an int. (I copied and pasted the following from a web page and then edited slightly...)


    The prototype for getchar() is as follows:

    Code:
     int getchar(void);
    As indicated by the void keyword in the fragment of code above, getchar() takes no arguments. It also returns an int. The fact that it returns an int is worth taking note of. The name getchar is a little misleading in that it could imply that a char is being returned. Indeed, the function gets characters, but does not return a char. Many new C programmers get caught on this one and assign the return value of getchar() to a char variable, instead of an int. Remember: when using getchar() be sure to always assign the return value to an int variable.

    Consider the char data type as opposed to an int. The char is a numeric integer data type. Kernighan and Ritchie state in their book The C Programming Language: Second Edition that, "By definition, chars are just small integers, so char variables and constants are identical to ints in arithmetic expressions." (pg 23) Also, a char is specifically meant for storing character data, but any integer type can be used as well as char, for the purpose of storing character data.(pg 16) This does NOT mean that chars and ints are interchangeable in all things. For our purpose, the main difference between the two is this: On a 32 bit machine a char is one byte while an int is four bytes.

    Consider that when you obtain data from the user, there has to be a suitable method of distinguishing between valid data, and the end of the file (ie, no more input). The function getchar() does return a special value when the end of the input is reached, and this value is called EOF (or end of file). EOF is defined in <stdio.h> and must be a value that will not be mistaken as a useful character that was entered by the user. At this point it is not necessary to worry about the actual value of EOF - that has already been taken care of when your compiler was put together - but here is where the importance of assigning the return value of getchar() to an int becomes clear; It takes space to hold the value of EOF, so now what happens when getchar() returns EOF as well as a character? The space will be used for the character, or the value of EOF, but there will not be room for both. This then, is the reason why you assign the return value of getchar() to an int in order to make room for any character returned plus EOF if necessary.
    Last edited by kermit; 03-29-2004 at 05:28 AM.

  6. #6
    Registered User joed's Avatar
    Join Date
    Mar 2004
    Posts
    59
    That's one heck of an indent.

    -Joe

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >That's one heck of an indent.
    Only wimps use small indents. If one tab is good, multiple tabs are great. Right?
    My best code is written with the delete key.

  8. #8
    Registered User linuxdude's Avatar
    Join Date
    Mar 2003
    Location
    Louisiana
    Posts
    926
    All tabs are eight characters and will be the <TAB> character. This makes locating where different blocks of code start and end easier. If you find that your code is indented too deeply, with more than three levels of indentation that cause the code to shift to the right of the screen too far, then you should fix this.
    source: Kernel Korner
    That is why I like 8 char indentations(the part in bold)
    P.S. Don't want to start a war again already happened in the generl discussions spot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Same old beginner question...
    By Sharmz in forum C Programming
    Replies: 15
    Last Post: 08-04-2008, 12:48 PM
  2. HELP!! NEw to Arrays/Functions.. LOST
    By felixgun in forum C++ Programming
    Replies: 4
    Last Post: 11-22-2006, 01:20 PM
  3. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  4. i'm totally lost
    By jlmac2001 in forum C++ Programming
    Replies: 5
    Last Post: 02-01-2003, 11:06 PM
  5. Beginner who is lost - functions
    By Unregistered in forum C Programming
    Replies: 4
    Last Post: 04-07-2002, 09:27 PM

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