View the step-by-step solution to:

Please choose an option between 1-5" no matter what selection I choose.

I cannot get my assignment to stop looping "Incorrect selection. Please choose an option between 1-5" no matter what selection I choose. I feel like I am really close but something is definitely wrong.


CODE IS AS FOLLOWS:



#include<stdio.h>

 

 

int main(void)

 

{

int choice;

int hoursworked;

 

#define rate1 8.75;

#define rate2 9.33;

#define rate3 10.00;

#define rate4 11.20;

#define tax1 0.15;

#define tax2 .2;

#define tax3 .25;

#define overtimerate 1.5;

 

 

   float rate, hours, gross, tax, net, overtime;

 

 

   printf("*******************************************************************n");

   printf("Enter the number corresponding to the desired pay rate or action:n");

   printf("1) $8.75/hr                   2) $9.33/hrn");

   printf("3) $10.00/hr                  4) $11.20/hrn");

   printf("5) quitn");

   printf("*******************************************************************n");

   scanf("%d, &choice");

 

   while(choice <1 || choice >5)

   {

       printf("Incorrect selection. Please choose an option between 1-5n");

   }

   if(choice > 1 || choice < 5)

   {

       printf("Enter amount of hours worked this week.n");

       scanf("%d, &hoursworked");

   }

 

   switch(choice)

   {

       case '1': rate1;

               break;

       case '2': rate2;

               break;

       case '3': rate3;

               break;

       case '4': rate4;

               break;

       case '5': return 0;

               break;

 

   }

 

   if(hoursworked > 40)

   {

      overtime = (hoursworked - 40)* rate * overtimerate;

      gross = (40 * rate) + overtimerate;

   }

   else

   {

       gross = hoursworked * rate;

   }

 

   if(gross<=300)

       tax = gross* tax1

   else if(gross <=450)

       tax = gross * tax2;

   if(gross>450)

       tax = gross * tax3;

 

   net = gross - tax;

 

   printf("Gross: $%.2f", gross);

   printf("Tax: $%.2f", tax);

   printf("Net: $%.2f", net);

 

   return 0;

 

}

Top Answer

Following is your corrected code: You should define all the constants outside of your main function globally. Then your loop... View the full answer

215.png

Sign up to view the full answer

Other Answers

The reason why it is looping at that point is because you have not included the memory allocation script for... View the full answer

The mistake is in the scanning... View the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online