Problem with a program.

I am new to C programming and am having a problem. I will paste the code then explain the problem.

//Kelly Qualls

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int menu_selection;
char name [20] ;
char address[30] ;
char city_state_ZIP[30];
void add_entry();
void delete_entry();
void find_entry();
void exit_out();
void error_message();
int main ()
{

cout << "Database system V.1.0\n\n";
cout << "1. Add a new entry:\n";
cout << "2. Delete an entry:\n";
cout << "3. Find an entry\n";
cout << "4. Exit:\n";
cout << "\n\n Please Enter Your Selection:>";
cin >> menu_selection;

if(menu_selection==1)
add_entry();
else if(menu_selection==2)
delete_entry();
else if(menu_selection==3)
find_entry();
else if(menu_selection==4)
exit_out();
else
error_message();
return 0;
}

void add_entry ()
{
cout << "Name:";
cin.getline(name,19);
cout << "Address:";
cin.getline(address,29);
cout << "City, State ZIP:";
cin.getline(city_state_ZIP,29);

}
void delete_entry ()
{
}
void find_entry ()
{
}
void exit_out ()
{
}
void error_message()
{
}

I just started the program but when I run it, it jumps from name to address without allowing the name to be entered. Can anyone tell me why? Thanks for the help.
Read this:
http://www.cplusplus.com/forum/articles/6046/

It has the answer and solutions.
Thanks for the help Firedraco.







int menu_1;
cout << "Name:";
getline(cin, name);
cout << "Address:";
getline(cin, address);
cout << "City, State ZIP:";
getline(cin, city_state_ZIP);

cout << "\n\n1. Main Menu\n";
cout << "2. Create another entry\n";
cout << "Please enter your selection:>";
cin >> menu_1;
cout << "\n\n";


This returns the following error in Visual c++.

array out.cpp(45) : error C2784: 'std::basic_istream<_Elem,_Traits> &std::getline(std::basic_istream<_Elem,_Traits> &,std::basic_string<_Elem,_Traits,_Alloc> &)' : could not deduce template argument for 'std::basic_string<_Elem,_Traits,_Alloc> &' from 'char'
1> c:\program files\microsoft visual studio 9.0\vc\include\string(527) : see declaration of 'std::getline'

for every line that has the getline code.

Don't use char arrays if you are going to use getline(). Like the article says, use getline() with std::strings
Thanks. Got it all worked out. Everything is working. Sorry for asking simple things. This is my first program in c++. I am reading as much as a can. THe only other programming I know is assembly so its all new to me. Thanks again
Topic archived. No new replies allowed.