Why wont the program let me keep inputting

why wont the program let me input a value for amount?

#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
using namespace std;

int main()
string date, payee, account_holder;
int amount;
cout<<"Date: ";

cout<<"Payee: ";

cout<<"Amount: ";

cout<<"Account Holder: ";

return 0;
Last edited on
What input are you giving the program?
when it asks for date i input a date for example: 12/25/17
then it asks for the payee so i imput for example: lewis E Smith
then the program outputs: Payee: Account Holder:
then the programs ends
The >> operator will only read one word so payee will get the value "lewis", but " E Smith" is still left in the buffer for the next input operations to read, so when the program tries to read the amount it fails because "E" is not a valid integer.

If you want to allow the payee to contain multiple words you might want to use std::getline.

getline(cin >> ws, payee);
Last edited on
Topic archived. No new replies allowed.