Simple problem please help!

I have this code but when I run the program it displays the first two cout lines without prompting the cin after I make choice==1. I'm sure my mistake is very simple and dumb, but I can't figure it out for some reason, please help!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
int main() {


	string School, Team, Conference;
	string inputSchool, inputTeam, inputConf, inputRecord;
	string searchSchool;
	char confirm;
	int choice, wins, losses;

	string input = "";
	string textFile = "BBall.txt";

	ifstream iFile;


	do{
		system("CLS");
		cout << "Please enter the choice you wish to continue with:\n";
		cout << "1 - Insert a node.\n";
		cout << "2 - Search for a node.\n";
		cout << "3 - Exit the program.\n\n";
		cin >> choice;

		if(choice == 1) {
			cout << "Please enter the name of the school you wish to add.\n";
			getline( cin, inputSchool);
			cout << "Please enter the Team Name.\n";
			getline( cin, inputTeam);
			//cin >> inputTeam;
			cout << "Please enter the team's record (Seperated by a space).\n";
			cin >> wins >> losses;
			//cin >> inputRecord;
			cout << "Please enter this school's conference.\n";
			getline( cin, inputConf);
			//cin >> inputConf;
		}
Use << std::endl instead of "\n", or put std::cout << std::flush; before the cin.

The issue is that until you have std::endl or std::flush, the data might not be written to the screen (due to the way buffered streams work).
It did not work, both cout lines still appear without me having a chance to input the cin.
Which lines appear, exactly? Also, could you repaste your most recent code? (just edit your first post)
first off bro if you wanna type this without typing std al the time add using namespace std; and anohte thing ou didnt even declare your libraries you need to add an iostream library for sure then after that you ay need a few others too. so the beginnig of your code should actally look like this:
#include <iostream> // this is your libraries.
using namespace std; //this is so you dont have to constantly type std::
int main();


those two top things are mainly what i see is wrong im sure you may know what those were at the top but i added side notes to kinda help declare incase you didnt
@xCod3x: Please do not encourage use of "using namespace std;"
@ l B: Ehh it's not that I'm encourageing it infanct it can be faulty but it does save time sometimes if you know exactly what your writing and what goes where, but down to the point if bbesase didn't want to go through and add std:: for the cout and cin it would possibly help on saving time.
Last edited on
It is a bad habit. Just because it doesn't hurt now doesn't mean it will not hurt later. Procrastination and short-sightedness should not be encouraged, ever ;)

http://www.parashift.com/c++-faq/using-namespace-std.html

http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-a-bad-practice-in-c
Topic archived. No new replies allowed.