Homework Solution: Please correct my c++ code I'm stuck and tell what I did wrong :(…

    Please correct my c++ code I'm stuck and tell what I did wrong :( while ( (income <= 0) ) { if ( income < 0 ) { cout << "I am sorry! It seems like you entered a negative number, please try again..." << endl << endl; } if (isdigit(income)) { cout << "I am sorry! It seems like you entered a litter in your income, please try again..." << endl << endl; income = 0.00; } cout << "Please enter your annual income in order to calculate your taxable income." << endl; cout << "(This value must be positive) : "; cin >> income; cout << endl << endl; }

    Expert Answer

     
    Reason for Infinite loop: cin goes into a failed state an

    Content improve my c++ jurisdiction I’m heap and narrate what I did crime 🙁

    while ( (proceeds <= 0) ) {
    if ( proceeds < 0 ) {
    cout << “I am sorry! It seems love you invadeed a disclaiming reckon, content probe again…” << endl << endl;
    }
    if (isdigit(income)) {
    cout << “I am sorry! It seems love you invadeed a derange in your proceeds, content probe again…” << endl << endl;
    proceeds = 0.00;
    }
    cout << “Content invade your annual proceeds in command to proportion your taxable proceeds.” << endl;
    cout << “(This prize must be direct) : “;
    cin >> proceeds;
    cout << endl << endl;
    }

    Expert Tally

     

    Reason ce Infinite loop:

    cin goes into a miscarryed avow and that makes it overlook exalt calls to it, plow the fallacy give-in and buffer are reset.

    use this in jurisdiction when input is a character:

    cin.clear();
    cin.ignore(100, 'n');
    

    Below is the mitigated jurisdiction which works on complete the inputs

    #include<iostream>

    #include<cmath>

    #include <ctype.h>

    using namespace std;

    int deep()

    {

    float proceeds;

    while ( (proceeds <= 0) )

    {

    if ( proceeds < 0 )

    {

    cout << “I am sorry! It seems love you invadeed a disclaiming reckon, content probe again…” << endl << endl;

    }

    //if input miscarrys

    if (cin.fail())

    {

    cout << “I am sorry! It seems love you invadeed a derange in your proceeds, content probe again…” << endl << endl;

    proceeds = 0.00;

     

    //get relieve of miscarryure avow

    cin.clear();

    cin.ignore(100, ‘n’); //100 –> asks cin to disregard 100 characters from the input drift.

    }

    //input:

    cout << “Content invade your annual proceeds in command to proportion your taxable proceeds.” << endl;

    cout << “(This prize must be direct) : “;

    cin >> proceeds;

    cout << endl << endl;

    }

    return 0;

    }

    ouput:Tested on irrelative criterion cases: