getline help

i have been stuck at this for almost an hour...can someone kindly tell me what am i doing wrong? at the getline(cin,name), when running the program it wont let me key in the name, it goes to system("pause") straight...
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
  #include <iostream>
#include <string>
using namespace std;

void new_account ()//create new account
{
	system ("cls");

	int hello;
	char account_type;
	string name;
	

	cout<<"CREATE NEW ACCOUNT"<<endl<<endl;
	cout<<"Please insert the following details: "<<endl<<endl;
	cout<<"Which type of bank account would you like to create?"<<endl;
	cout<<"(Enter S for savings, C for current, T for trading)"<<endl;
	
	cout<<"Please enter your full name: ";
	getline (cin,name);
	cout<<name;
	
	system("pause");






	

}

void edit_details ()//edit existing account holder details
{
	system ("cls");
}

void deposit_money ()//deposit money to an account
{
}

void withdraw_money ()//withdraw money from an account
{
	system ("cls");
}

void check_balance ()//check balance
{
}

void close_account ()//close an account
{
	system ("cls");
}


int main()//menu selection
{
	char menu;
	

	
	
	

	cout<<"Welcome to Utar Bank Account System"<<endl<<endl;
	cout<<"1) Create new bank account"<<endl;
	cout<<"2) Edit existing account holder details"<<endl;
	cout<<"3) Deposit money to an account"<<endl;
	cout<<"4) Withdraw money from an account"<<endl;
	cout<<"5) Check Balance"<<endl;
	cout<<"6) Close an account"<<endl;
	cout<<"7) XXXXX"<<endl;
	cout<<"8) XXXXX"<<endl;
	cout<<"9) XXXXX"<<endl;
	cout<<"0) Exit"<<endl;

	cin>>menu;

	switch (menu)
	{
	case '1': new_account ();
		break;

	case '2': edit_details ();
		break;

	case '3': deposit_money ();
		break;

	case '4': withdraw_money ();
		break;

	case '5': check_balance ();
		break;

	case '6': close_account ();
		break;

	case '7': close_account ();
		break;

	case '8': close_account ();
		break;

	case '9': close_account ();
		break;

	case '0': exit(0);
		break;
		
	default: cout<<"Wrong selection, please try again.";
			 system("pause");
			 

	}//switch break

	
	
	system("cls");


	return 0;




}
First thing, you should never use the system() command outside of fun coding or school assignments. Try putting cin.ignore() before the getline command to clear the buffer. Either way, I believe that cin >> string reads white space separated words.
Last edited on
thanks!
No problem!
Topic archived. No new replies allowed.