• Advertisement

Archived

This topic is now archived and is closed to further replies.

Why does this require my to press enter twice?

This topic is 5234 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well after stoping on programming for a long time I decided to "relearn" C++. I wrote this code quickly but what I dont understand is why you have to press enter twice after you enter in the string. Here is the code
#include
#include
using namespace std;

int main()
{
	const int SEMHOURFEE = 100;
	const int ROOMBOARD  = 1800;
	string name          = "";
	int hours            = 0;
	int total            = 0;

	//enter input items
	cout << "Enter student name: "<< endl;
	getline(cin, name);
	cout << "Enter hours enrolled: ";
	cin >> hours;

	//calculate total owed
	total = hours * SEMHOURFEE + ROOMBOARD;

	//display output items
	cout << "Student name: " << name << endl;
	cout << "Total due: " << total << endl;


	return 0;
}
  
I just dont get it. I just hope I did the message board code thing right. [edited by - Thrust on October 22, 2003 5:52:57 PM]

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
What''s wrong with cin >> name;
Why getline(cin,name)?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can actually, RTFM.

Share this post


Link to post
Share on other sites
Wow relearning C++ using Visual C++ rather than Codewarrior is going to be harder than I though.

Share this post


Link to post
Share on other sites

  • Advertisement