-
banking progrram
hi, i made this banking program but i can't make the user specify the name of the account to be ceated here's the code i need any help and any ideas, thanks
<code>
#include<fstream.h>
#include<iostream.h>
#include <conio.h>
#include <string.h>
int main()
{
int choice;
char crt[90];
char eee[5];
cout<<" Welcome to the new banking program \n";
cout<<"---------------------------------------------------------------------\n";
cout<<"Please choose from the below options:\n";
cout<<"1. Create a new account.\n";
cout<<"2. Open an existing account.\n";
cout<<"3. Edit an existing account.\n";
cout<<"4. Information about the programmer.\n";
cout<<"5. Quit.\n";
cout<<"----\n";
cout<<"Your Choice: ";
cin>>choice;
cin.ignore();
cout<<" -------------------------------------------------------------\n";
if(choice==1)
{
cout<<"Please type in your account name:\n";
cin.getline(crt, 90);
ofstream a_file("<<crt", ios::noreplace);
main();
}
}
</code>
-
Well, for starters you're using the deprecated headers, it should be like this:
Code:
#include <iostream>
#include <fstream>
#include <conio.h>
//#include <string> no string library functions used
using namespace std; //nescessary
...
ofstream a_file(crt);
-
Also the recursion (calling main() at the end of main), should be avoided when the problem can be solved another way.
here are my suggestions
Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int choice;
char crt[90];
//char eee[5];
// Unneccessary as of yet
cout<<" Welcome to the new banking program \n";
cout<<"---------------------------------------------------------------------\n";
cout<<"Please choose from the below options:\n";
cout<<"1. Create a new account.\n";
cout<<"2. Open an existing account.\n";
cout<<"3. Edit an existing account.\n";
cout<<"4. Information about the programmer.\n";
cout<<"5. Quit.\n";
cout<<"----\n";
cout<<"Your Choice: ";
cin>>choice;
cin.ignore();
cout<<" -------------------------------------------------------------\n";
if(choice==1)
{
cout<<"Please type in your account name:\n";
cin.getline(crt, 90);
ofstream a_file(crt, ios::noreplace);
// just crt here will do what you expect, create a file with the name crt
}
cout << "The name of your new account: " << crt << endl;
return 0;
//main(); recursive, and with no "break" to stop is a bad idea
}
Ultimately, if you plan to expand the menu and include all the options, I would reccomend that you look into the subject of Object-oriented-programming (OOP), and Classes.
-- Placid