Jump to content
  • Advertisement

Archived

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

Thrust

Why does this require my to press enter twice?

This topic is 5453 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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!