Hello, reader. I've been learning c++ like a mother recently and, believe it or not, I've encountered a problem! Or, more of a writers block.
note:You don't have to read all this crap, my question is at the end of this post.
I'm making an account management program to better my skill in programming.
It accepts input from the user for personal information then saves it to a .txt file.
I'll show you the code so you can get a better idea of what I'm talking about:
Code:
/*
Account Management.
This is an information database program.
By Jacob Keller
March 12, 2008
*/
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
int main()
{
char yes[10];
char name[50];
char lastname[50];
char fullname[100];
char phonenumber[11];
char address[100];
ofstream account_a ("accounts.txt", ios::app);
cout<<"To create an account, type 'new'. ";
if(strcmp(yes,"new")==0)
{
cout<<"Enter first name: \n";
cin.getline(name,50);
cout<<"Enter last name: \n";
cin.getline(lastname,50);
cout<<"Enter home phone number: \n";
cin.getline(phonenumber,11);
cout<<"Enter address: \n";
cin.getline(address,100);
//Group info.
strcat(fullname,name);
strcat(fullname," ");
strcat(fullname,lastname);
account_a<<"Name: " <<fullname<<". Address: "<<address<<". Phone Number: "<<phonenumber<<".";
cout<<"New account saved to accounts.txt \n";
}
cin.get();
}
Right now it's a mess and I haven't got half the features done, but what it's suppose to do is open up, give you the option to "create an account", and then save it.
But, (because of cin.get(); I believe) it closes once you press enter, not giving the user a chance to create an account. The only way I see of resolving this problem is by hitting a key without hitting the enter key.
So is there a way to make the program wait for the user to press a specific key instead of using enter? If so, please tell me.