[Resolved] Basic I/O problem in C++

Started by
17 comments, last by OpperationQuak 15 years, 5 months ago
Resolved Hi there i am writing a program to write user inputted data to a database running in a loop but everytime it runs the loop more than once you dont get a chance to enter the first set of information and it goes straight to the second set of information eventho they are both using the same function to get the input heres what i get when i run the program: image my code is in a later post any help would be greatly appreciated [Edited by - OpperationQuak on October 29, 2008 7:22:38 AM]
Advertisement
You're making a basic problem very complicated. My advice is to just use cin directly instead of getInput, until you find yourself with duplicated code that needs to be factored out.
i understand that it does look like im making a simple problem complicated but the program as a whole isnt just going to write a database

also if i just use cin i will never find the problem and therefore wont learn what i have done wrong
Quote:Original post by OpperationQuak
i understand that it does look like im making a simple problem complicated but the program as a whole isnt just going to write a database
The only thing that your getInput fnction accomplishes is to needlessly complicate a very simple problem. Here is a simple refactoring of your code, with no need for get input, no need for a separate parsing structure, and simpler to boot:
	do	{		input userInput;		cout << "Enter Name: "		getline(cin, custDetails.name);		cout << "Enter Address: "		getline(cin, custDetails.address);		cout << "Enter Phone Number: "		getline(cin, custDetails.phoneNum);		cout << "Enter D.O.B: "		cin >> custDetails.dob;				cin >> std::boolalpha >> cont;	}	while(cont == true);

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

i get what your saying and i know i could do that but i want to find out whats causeing the problem with the function

if i make it an infinite loop and stop getting the date and continue prompt it works fine so it something to do with one of the 3 lines of code im omiting

anyone have any ideas without telling me to stop using getInput?
i managed to get it to work by taking getline out but now i need an alternative to getline

any solutions
#define NAME_MAX 256#define ADDR_MAX 256struct Customer{   char Name[NAME_MAX];   char Address[ADDR_MAX];   int PhoneNo;   int DOB;};void prompt(const char* msg, bool newLine = true){   if(newLine)   {      cout << msg;   }   else   {      cout << msg << "\n";   }}bool GetEntry(Customer* customer){   prompt("Enter Name: ");   cin.getline(customer->Name, NAME_MAX);   prompt("Enter Address: ");   cin.getline(customer->Address, ADDR_MAX);   prompt("Enter Phone Number: ");   cin >> customer->PhoneNo;   prompt("Enter D.O.B: ");   cin >> customer->DOB;   bool r_val;   cin >> rVal;}int main(){   while(true)   {      Customer c;      if(!GetEntry(&c))         break;   }}   return r_val;}


[Edited by - staticVoid2 on October 24, 2008 4:48:26 PM]
that doesnt work either staticVoid
it still has the same problem
witch sugests more that its a problem with getline
or the way im using it
I dunno then, maybe you could try reformatting your hard drive. or did you miss any semi-colons?, that could effect runtime performance.
LOL craig
just lol

but seriously this is a pain in the arse

This topic is closed to new replies.

Advertisement