0

I'm working on a homework assignment for my C programming class, so I'm not looking for straight answers, rather instructions or guidance. My code is pretty elementary, we've only used C for 3 weeks now, so I apologize ahead of time. So far we've only covered conditionals, loops, counters, switch/break/continue for multiple selection, logical operators, and reading characters, so if you mention something other than this, I'll probably be clueless.

 7 #include <stdio.h> 8 #include <math.h> 9 10 int main(void) 11 { 12 13 /*Define variables*/ 14 int response, btaxrate, taxrate; 15 float income,taxamount, netincome; 16 17 18 /* Start the dowhile loop for running the program more than once if the user wants to */ 19 do{ 20 21 22 /*Grab the income amount from the user */ 23 printf("Enter the annual income: "); 24 scanf("%f", &income); 25 /* Check to make sure it is above 0 with a while loop */ 26 while(income <= 0) 27 { 28 printf("Invalid income, enter the income again: "); 29 scanf("%f", &income); 30 } 31 32 /* Grab the base taxrate from the user */ 33 printf("Enter the base tax rate: "); 34 scanf("%d", &btaxrate); 35 /* Check to make sure it is <10 or >30 with a while loop */ 36 while(btaxrate < 10 || btaxrate > 30) 37 { 38 printf("Invalid base tax rate, enter the tax rate again: "); 39 scanf("%d", &btaxrate); 40 } 41 42 /* Determine what the taxrate is based on the income amount */ 43 if(income >= 0 && income < 50000) { 45 taxrate=btaxrate; 46 } 47 if(income >= 50000 && income < 100000) 48 { 49 taxrate=btaxrate+10; 50 } 51 if(income >= 100000 && income < 250000) 52 { 53 taxrate=btaxrate+20; 54 } 55 if(income >= 250000 && income < 500000) 56 { 57 taxrate=btaxrate+25; 58 } 59 if (income >= 500000) 60 { 61 taxrate=btaxrate+30; 62 } 63 64 65 /* Equations for taxamount and netincome */ 66 taxamount=(float)(income*taxrate)/(float)100; 67 netincome=(float)income-(float)taxamount; 68 69 70 /* Tell them their tax rate, how much they pay in taxes, and their net income after taxes*/ 71 printf("Your tax rate is: %d%%", taxrate); 72 printf("\nYou pay $%.2f in taxes.", taxamount); 73 printf("\nAfter taxes your net income is: $%.2f", netincome); 74 75 76 /* Ask the user if they want to run the program again, get a value for yes if so */ 77 printf("\nDo you want to continue? (0:Exit 1:Continue:)"); 78 scanf("%d", &response); 79 80 81 } /* End do */ 82 83 /* While part of dowhile to see if the program runs again */ 84 while(response == 1); 

I'm supposed to display the highest value, lowest value, and average of taxamount that was determined depending on how many times the user re-ran the program, then print it. So, for example, if they ran it 5 times (by pressing 1 to continue) and the values of taxamount were 15000, 8000, 20000, 35000, and 100000, how would I print "100000 is the highest, 8000 is the lowest, and the average is 35600"?

4
  • 2
    what's there with all the haha, LOL part? Commented Feb 20, 2015 at 11:40
  • 2
    All the comments in this program are redundant.. Commented Feb 20, 2015 at 12:00
  • It makes text less serious, if you don't like it, don't read it. And yes, I know, they're very redundant. The class I'm in requires them. Commented Feb 20, 2015 at 12:03
  • @Nick: first of all: this is a serious platform, so if you don't like it, don't post on it. And what does the class require? It requires you to do redundant comments? or it requires you to do comments? the first appears to me like an strange requirement. The second is a good requirement but then it is to avoid doing redundant comments (what it is at all IMPOW) Commented May 12, 2015 at 12:06

1 Answer 1

3

You can just make a temporary variable, in the first iteration you save there the value of taxamount and in successive iterations you check if the new value is greater and update it accordingly.

From there I think you can guess how to do the rest of the calculations.

Sign up to request clarification or add additional context in comments.

2 Comments

Good answer because it addresses the issue, but the OP didn't deserve one.
@Nick, You are not supposed to use bad language. You might get banned from here.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.