I am working on an assignment that I currently have. I am using cin.getline to input the title of a book. The problem is every time I run it here is how it shows up in the command prompt Title: Price: $_

Why is it doing this? cin.getline seems to be the only function that can read an entire line with spaces.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{


   const int SIZE = 25;
   char BookTitle[SIZE];

   int BookQuantity;

   double price;


   cout << "Enter book quanity" << endl;
   cin >> BookQuantity;

   cout << "Title: ";
   cin.getline(BookTitle, SIZE);

   cout << "Price: $";
   cin >> price;

return 0;
system("PAUSE");
}

This Daniweb tutorial explains what is happening and how to fix it: "Flushing" the input stream

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.