Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8557339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:33:08+00:00 2026-06-11T15:33:08+00:00

I have an issue with a nested if statement when inputting values 60000.01, 70000.01,

  • 0

I have an issue with a nested if statement when inputting values 60000.01, 70000.01, 75000.01 and 88000.01 the RaisePrcnt Values do not get printed to the console. I don’t see a flaw with the structure of the nested if, and any other value besides those specific ones work fine.

#include<stdio.h>
#include<stdlib.h>

void main()
{
    // Employee and Department name variable declarations.
    char Name1[25], Dept1[25];  

    /* Variable declarations for current yearly income, raise percentage, 
    new raise amount and the new yearly pay amount.*/
    float Income1, NewPay1;
    float RaisePrcnt1 = 9.7, RaisePrcnt2 = 8.5, RaisePrcnt3 = 7.2;
    float RaisePrcnt4 = 6.3, RaisePrcnt5 = 5.9, Percentage = 0;

    /*Initialize and declare variables to calculate the total current
    yearly incomes, total raise amounts and total new pay amounts for
    all 4 employees.*/
    float IncomeTotal = 0;
    float RaiseTotal = 0; 
    float PayTotal = 0;

    // Display program title.
    printf("\t\t\t\tINCOME CALCULATOR\n\n"); 

    // User directive.
    printf("\t\t************************************************\n");
    printf("\t\tPLEASE ENTER THE FOLLOWING EMPLOYEE INFORMATION: "); 
    printf("\n\t\t************************************************\n\n");

    /************************************************************
    BEGIN COLLECTING INFORMATION ON EMPLOYEE NUMBER 1.          *
    ************************************************************/
    printf("\t\tEmployee Number 1: \n");
    printf("\t\t________________________________________________\n");

    printf("\n\t\tName: \t\t\t"); // Prompt user for Name.
    gets(Name1); // Reads input for Name to the enter key.

    printf("\n\t\tDepartment: \t\t"); // Prompt user for Department Name.
    gets(Dept1); // Reads Department Name input to the enter key.

    // Prompt user for Current Yearly Income input.
    printf("\n\t\tCurrent Yearly Income: \t"); 
    scanf("%f", &Income1); // Reads Current Income input.

    // Prompt user for the Raise Percentage.
    //printf("\n\t\tRaise Percentage: \t");
    //scanf("%f", &RaisePercent1); // Reads Raise Percentage input.


    if(Income1 < 0 && Income1 != 0){
       printf("%0.1f The Income Amount entered is INVALID. \t");
    }else
        if(Income1 >= 0 && Income1 <= 60000){
           printf("%0.1f", RaisePrcnt1);
        }else
           if(Income1 >= 60000.01 && Income1 <= 70000){
              printf("%0.1f", RaisePrcnt2);
           }else
              if(Income1 >= 70000.01 && Income1 <= 75000){
                 printf("%0.1f", RaisePrcnt3);
              }else
                 if(Income1 >= 75000.01 && Income1 <= 88000){
                    printf("%0.1f", RaisePrcnt4);
                 }else
                    if(Income1 >= 88000.01){
                    printf("%0.1f", RaisePrcnt5);
                    }



 //Percentage = (Income1 * RaisePrcnt1);
 //Percentage = (Income1 * RaisePrcnt2);
 //Percentage = (Income1 * RaisePrcnt3);
// Percentage = (Income1 * RaisePrcnt4);
//Percentage = (Income1 * RaisePrcnt5);





    // Calculate and print the new Raise Amount for Employee Number 1.
    //RaiseAmt1 = (Income1 * RaisePercent1) / 100;
 //printf("\n\tBased on the information you have entered for Employee Number: 1\n"); 
//  printf("\t________________________________________________________________\n");
    //printf("\n\tThe New Raise Amount is: \t$ %0.2f", RaiseAmt1); 

    // Calculate and print the New Income Amount for Employee Number 1.
    //NewPay1 = Income1 + RaiseAmt1;
    //printf("\n\tThe New Pay Amount is: \t\t$%0.2f", NewPay1); 
    //printf("\n\n");

    // Calculate and incorporate Employee 1 figures into final totals.
    //IncomeTotal = IncomeTotal + Income1;
    //RaiseTotal = RaiseTotal + RaiseAmt1;
    //PayTotal = PayTotal + NewPay1;
    /*END EMPLOYEE 1.*******************************************/

    //fflush(stdin);


    // Title for totals.
    //printf("\n\n\t\t************************************************\n");
    //printf("\t\t\tINCOME TOTALS FOR ALL EMPLOYEES"); 
    //printf("\n\t\t************************************************\n\n");

    /*Calculate and print all totals for the 4 employees.*/
    //printf("\tCurrent Yearly Incomes \tTotal: $%10.2f", IncomeTotal);
    //printf("\n\tRaise Amounts \t\tTotal: $%10.2f", RaiseTotal);
    //printf("\n\tNew Yearly Incomes \tTotal: $%10.2f", PayTotal);
    //printf("\n\n");


    system("PAUSE");
    //return (0);

} // End main.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T15:33:09+00:00Added an answer on June 11, 2026 at 3:33 pm

    This is a floating point precision error (also covered well here). Just because you input Income1 as 60000.01 does not mean Income1 >= 60000.01 will be true.

    Indeed, as you currently have the if statements constructed, there is no need for that comparison- once you’ve reached that point you already know that Income1 is not less than 60000, thanks to the else. Just do:

    if(Income1 < 0){
       printf("%0.1f The Income Amount entered is INVALID. \t");
    } else if (Income1 <= 60000){
           printf("%0.1f", RaisePrcnt1);
    }else if (Income1 <= 70000){
              printf("%0.1f", RaisePrcnt2);
    }else
    

    and so on. (Also note that your deep indentation was unnecessary, as they weren’t actually nested ifs).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue which I could not find answer for across the web.
So what the issue is, i have 2 for loops one nested within another.
I have strange issue with nested left-joins in postgresql... It's hard to explain, but
I have a model Issue and a nested Model Relationship In the issue.rb I
I have the issue that i have a viewmodel (MasterViewModel) with a nested viewmodel
Looking for help with a tripple nested repeater logic issue I have. Background I
so I have a tricky issue here I'm not sure how to solve. I
Here's my issue: I have nested lists, and I want to grab the size
I have nested ajax calls that are not working in ie7. They work fine
I have created a nested list with drag/drop functionality. My issue is that I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.