If the program is being run the "cin>>answerBoss;" runs just fine but right after that input the program skips the next input that reads "cin>>overTime;" I can't figure out what is causing this to happen.

#include <iostream>
#include <string>

using namespace std;

int answerBoss, overTime;
const int MONEY_AVAILABLE=20.00;
int hourPay=8.00;
int halfPay=hourPay/2.00;
int gameCost=60.00;
int hourHalf=hourPay+halfPay;
int overTotal=hourHalf*overTime;
int finalAmount=MONEY_AVAILABLE+overTotal;


int main()


    {


    cout<<"You have saved $"<<MONEY_AVAILABLE<<"."<<endl;

    cout<<"\nBut you want to buy a game that costs $"<<gameCost<<".\n"<<endl;

    cout<<"\nSo you will need $"<<gameCost-MONEY_AVAILABLE<<" to afford the vide game.\n"<<endl;

    cout<<"Durring that same day your boss calls you to work over-time"<<endl;

    cout<< "Your answered :"<<endl;

    cin>>answerBoss;

    cout<<"You're Boss replies by saying that he will pay you hour and half for the hour, \nwhich equals to the amount of $"<<hourHalf<<endl;

    cout<<"Not exceding 8 hours you agreed to work for: "<<endl;

    cin>>overTime;

    cout<<overTime<<" hours"<<endl;

    cout<<"after your boss payed you $"<<overTotal<<std::endl;

    cout<<"At the end of the day you ended with an total of $"<<finalAmount<<endl;

    if (finalAmount>=gameCost)
    { 
        cout<<"Enough to go buy the game and still have $"<<finalAmount-gameCost<<" to spend on something else."<<endl;
    } else {
        cout<<"You did not up making enough money, you need $"<<gameCost-finalAmount<<" to afford the game."<<endl;
    }


    return 0;


    }

cin>>overTime; won't get executed if you enter bad values for cin>>answerBoss;

In your code, the input data is expected to be an integer, if you supply anything else, it won't run the 2nd cin.

You need to change your int asnwerboss to char[20] answerboss or string answerboss.

There might be a stray character on the input stream. Try to use cin.ignore(); before the second input.

Vicentas you are right. Thank you!

@mike_2000_17 I needed to change the int to char to fix the error. But cin.ignore(); will come in usefull thank you.

cin>>answerBoss; is reading an integer. When it gets to the first character that does not fit the pattern for an integer, it stops reading, and puts the naughty character back on the input stream. This would include the new-line character at the end of the input stream. To get around this, call cin.ignore(); before each call to cin >>. This will tell cin to empty the line of input and the next time it needs characters it will as the user for them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.