Navigation

    ask avan logo
    • Register
    • Login
    • Search
    • Categories
    • Unsolved
    • Solved

    why this code is not working guys!

    Coding Question & Answers
    2
    3
    24
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • AshutoshxxTeotia
      AshutoshxxTeotia last edited by

      #include<stdio.h>
      int main()
      {
         int grossPay,tax1,tax2,tax3,extraHour,workingHour=40,TworkingHour,pay1,pay2,income1,totalTax,netPay,grossPay;
         printf("Enter the hours you have worked today");
         scanf(" %d",&TworkingHour);
         extraHour=TworkingHour-workingHour;
         pay1=workingHour*12;
         pay2=extraHour*18;
         grossPay=pay1+pay2;
         if(grossPay<=300)
         {
             tax1=grossPay*0.15;
             totalTax=tax1;
             netPay=grossPay-totalTax;
             printf("GROSS PAY$%d/nTAX$%d/nNET PAY$%d",grossPay,tax1,netPay);
         }
         else if(grossPay>300 && grossPay<=450)
         {
             tax1=300*0.15;
             income1=grossPay-300;
             tax2=income1*0.20;
             totalTax=tax1+tax2;
             netPay=grossPay-totalTax;
             printf("GROSS PAY$%d/nTAXES$%d,$%d/nNET PAY$%d",grossPay,tax1,tax2,netPay);
         }
         else if(grossPay>450)
         {
             tax1=300*0.15;
             tax2=150*0.20;
             income1=grossPay-450;
             tax3=income1*0.25;
             totalTax=tax1+tax2,tax3;
             netPay=grossPay-totalTax;
             printf("GROSS PAY$%d/nTAXES$%d,$%d,$%d/nNET PAY$%d",grossPay,tax1,tax2,tax3,netPay);
         }
         else
         {
             printf("Invalid pay");
         }
      
         return 0;
      }
      

      Screenshot (80).png

      Reply Quote 0
        1 Reply Last reply

      • avan
        avan last edited by

        I found the following stackoverflow answer: https://stackoverflow.com/questions/8124682/error-redeclaration-with-no-linkage

        I am going to quote the quote

        "You can't have two global variables with the same name in C program. C might allow multiple definitions in the same file scope through the tentative definition rule, but in any case all definitions will refer to the same variable."

        So grossPay is probably declared somewhere else already.

        I hope this helps.

        Reply Quote 0
          1 Reply Last reply

        • avan
          avan last edited by

          I found the following stackoverflow answer: https://stackoverflow.com/questions/8124682/error-redeclaration-with-no-linkage

          I am going to quote the quote

          "You can't have two global variables with the same name in C program. C might allow multiple definitions in the same file scope through the tentative definition rule, but in any case all definitions will refer to the same variable."

          So grossPay is probably declared somewhere else already.

          I hope this helps.

          Reply Quote 0
            1 Reply Last reply

          • AshutoshxxTeotia
            AshutoshxxTeotia last edited by

            you are right bro I got it just look at the last variable in the same line.

            Reply Quote 0
              1 Reply Last reply

            • First post
              Last post