banking2

This is a discussion on banking2 within the C++ Programming forums, part of the General Programming Boards category; can any1 tell em wut's the wrong with the variables in this code, it has 13 errors, and also i ...

  1. #1
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    Unhappy banking2

    can any1 tell em wut's the wrong with the variables in this code, it has 13 errors,
    and also i need to know how to get from b_file more than 1 line,
    i'll be pleased if noone takes the code 4 himself.
    Code:
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    	struct database
    {
    	int choice;
    	char crt[90];
    	char fstname[90];
    	char lstname[90];
    	char bd[90];
    	char mon[90];
    	char str[90];
    	char opn[90];
    	int x;
    	char data[1000];
    };
    	int main()
    {
    		database input;
    	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>>input.choice;
    			cin.ignore();
    cout<<" -------------------------------------------------------------\n";
      if(choice==1)				
      {
    	cout<<"Please type in your account name: * please note u need to type .txt after the file name\n";		
    	cin.getline(input.crt, 90);
    	  cout<<"First name:\n";		
    	  cin.getline(input.fstname, 90);
    	  cout<<"Last Name:\n";		
    	  cin.getline(input.lstname, 90);
    	  cout<<"BirthDate\n";		
    	  cin.getline(input.bd, 90);
    	cout<<"Please type in the amount of money you want to deposit:\n";
    	cin.getline(input.mon, 90);
    	ofstream a_file(input.crt, ios::noreplace);  
    	strcat(input.fstname, " ");
    		strcat(input.fstname, database.lstname);
    	a_file<<"Full name: " <<input.fstname <<"\n";
    	a_file<<"Birthdate: " <<input.bd <<"\n";
    	a_file<<"Amout of money: " <<input.mon;
    	a_file.close();                           
    	for(int database.x=0;x<101;x++) 
    	{
    		cout<<input.x<<endl;
     } 
    
    	cout<<"The new account has been saved\n";
    		cout<<"---------   *   ____________    *   ---------\n";
    	
    	main();
    				
    			}
      if(choice==2)
      {
    	  cout<<"Please Type the name of the account, note .txt must be included:\n";
    		  cin.getline( input.opn, 90);
    	  ifstream b_file(input.opn,  ios::nocreate);
    	  cout<<"\n";
    	  for(int input.x=0;x<101;x++);
    	{
    		cout<<x<<endl;
     } 
    	  cout<<input.opn <<"Opened, the data stored is:\n";
    	  b_file.get(input.data, 1000);
    	  cout<<input.data;
    	  b_file.close();
      }
    
    
    
    
    
    }
    Last edited by sweet2awy; 07-24-2003 at 11:21 PM.
    me

  2. #2
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    use these headers and namespace
    Code:
    #include<fstream>
    #include<iostream>
    #include<conio.h>
    #include<string>
    
    using namespace std;
    Instead of
    Code:
    if(choice==1)
    use
    Code:
    if(input.choice==1)

    This is wrong
    Code:
    strcat(input.fstname, database.lstname);
    try
    Code:
    strcat(input.fstname, input.lstname);
    I have no idea what your doing here
    Code:
    for(int database.x=0;x<101;x++) 
    {
      cout<<input.x<<endl;
    }
    database is the name of the struct, so database.x wont work. are you trying to output the input.x number 101 times ? confussed..

  3. #3
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    Post i did

    i did these things it now has 1 errors,
    but of course i added alot to the code i want to put a new function in themain function i wrote it like that

    Code:
               int quest()
    {
    bla 
    bla
    bla
    }
    it says wrong function definitions.
    Last edited by sweet2awy; 07-25-2003 at 10:27 AM.
    me

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    I would advice you to get an error free code before starting to add even more code. Could you post your current code with error message.

  5. #5
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    yea here it is

    Code:
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    	struct database
    {
    	int choice;
    	char crt[90];
    	char fstname[90];
    	char lstname[90];
    	char bd[90];
    	char mon[90];
    	char str[90];
    	char opn[90];
    	int x;
    	char data[1000];
    	char qui;
    	int c;
    };
    	int main()
    {
    		database input;
    	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. Information about the programmer.\n";
    		cout<<"4. Quit.\n";
    		cout<<"----\n";
    		cout<<"Your Choice: ";
    			cin>>input.choice;
    			cin.ignore();
    cout<<" -------------------------------------------------------------\n";
      if(input.choice==1)				
      {
    	cout<<"Please type in your account name: * please note u need to type .txt after the file name\n";		
    	cin.getline(input.crt, 90);
    	  cout<<"First name:\n";		
    	  cin.getline(input.fstname, 90);
    	  cout<<"Last Name:\n";		
    	  cin.getline(input.lstname, 90);
    	  cout<<"BirthDate\n";		
    	  cin.getline(input.bd, 90);
    	cout<<"Please type in the amount of money you want to deposit:\n";
    	cin.getline(input.mon, 90);
    	ofstream a_file(input.crt, ios::noreplace);  
    	strcat(input.fstname, " ");
    		strcat(input.fstname, input.lstname);
    	a_file<<"Full name: " <<input.fstname <<"\n";
    	a_file<<"Birthdate: " <<input.bd <<"\n";
    	a_file<<"Amout of money: " <<input.mon;
    	a_file.close();                           
    	for(int x=0;x<101;x++) 
    	{
    		cout<<input.x<<endl;
     } 
    
    	cout<<"The new account has been saved\n";
    		cout<<"---------   *   ____________    *   ---------\n";
    	
    	main();
    				
    	}
      if(input.choice==2)
      {
    	  cout<<"Please Type the name of the account, note .txt must be included:\n";
    		  cin.getline( input.opn, 90);
    	  ifstream b_file(input.opn,  ios::nocreate);
    	  cout<<"\n";
    	  for(int x=0;x<101;x++);
    	{
    		cout<<input.x<<endl;
     } 
    	  cout<<input.opn <<"Opened, the data stored is:\n";
    	  b_file.get(input.data, 1000);
    	  cout<<input.data;
    	  b_file.close();
      }
    
    
    if(input.choice==3)
    {
    	cout<<"Information about the programmer:\n";
    	cout<<"---------------------------------\n";
    	cout<<"I am a beginner in programming totaly new to it, I found it alot injoyable and chalenging I was in Webdesigning only, but now I'm trying to get my interests to cover every single bit in the computers, thanks.\n";
    	cout<<"OK, now here is my profile:\n";
    	cout<<"Name:  Shady M. Philip\n";
    	cout<<"Birthdate: 25/1/1988\n";
    	cout<<"Interests:\n";
    	cout<<"		* Computers and Internet.\n";
    	cout<<"		* Programming and webdesign.\n";
    	cout<<"		* Goin' out.\n";
    	cout<<"		* Movies.\n";
    	cout<<"		* Songs.\n";
    	cout<<"		* Chalenges.\n";
    	cout<<"		* Having alot of friends.\n";
    
    	cout<<"Sorry there's not any way to contact me except if you find this program in a website you can post to it and contact me through there, Have fun.\n";
    
    }
    
    if(input.choice==4)
    {
    	int quest()
    	{
    		database input
    	cout<<"Are you sure you want to Quit? y or n";
    	cin>>input.qui;
    
    	if(input.qui==y||yes)
    	
    	{
    		cout<<"ByeBye";
    		for(int input.c=0;x<11;x++) 
    	{
    		cout<<input.x;
     } 
    return 0;
    	}
    	if(input.qui==n||no)
    	{
    		main();
    	}
    	else
    	{
    		cout<<"This is not an option\n";
    		quest();
    			}
    
    	}
    }
    }

  6. #6
    Registered User
    Join Date
    Oct 2002
    Posts
    291
    This is how you make a function.
    Code:
    int quest(); //prototype
    
    int main()
    {
    
      quest();
      return 0;
    }
    
    int quest()
    {
      //place code inside here
    }
    Also, this code looks wrong aswell
    Code:
    if(input.qui==y||yes)
    I cant seem to find where you declare yes
    Code:
    if(input.qui=="y")

  7. #7
    Registered User
    Join Date
    Jul 2003
    Posts
    13

    new code

    here's da code

    Code:
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    	struct database
    {
    	int choice;
    	char crt[90];
    	char fstname[90];
    	char lstname[90];
    	char bd[90];
    	char mon[90];
    	char str[90];
    	char opn[90];
    	int x;
    	char data[1000];
    	char qui;
    	int c;
    };
    
    	
    	
    	int main()
    {
    		database input;
    	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. Information about the programmer.\n";
    		cout<<"4. Quit.\n";
    		cout<<"----\n";
    		cout<<"Your Choice: ";
    			cin>>input.choice;
    			cin.ignore();
    cout<<" -------------------------------------------------------------\n";
      if(input.choice==1)				
      {
    	cout<<"Please type in your account name: * please note u need to type .txt after the file name\n";		
    	cin.getline(input.crt, 90);
    	  cout<<"First name:\n";		
    	  cin.getline(input.fstname, 90);
    	  cout<<"Last Name:\n";		
    	  cin.getline(input.lstname, 90);
    	  cout<<"BirthDate\n";		
    	  cin.getline(input.bd, 90);
    	cout<<"Please type in the amount of money you want to deposit:\n";
    	cin.getline(input.mon, 90);
    	ofstream a_file(input.crt, ios::noreplace);  
    	strcat(input.fstname, " ");
    		strcat(input.fstname, input.lstname);
    	a_file<<"Full name: " <<input.fstname <<"\n";
    	a_file<<"Birthdate: " <<input.bd <<"\n";
    	a_file<<"Amout of money: " <<input.mon;
    	a_file.close();                           
    	for(int x=0;x<101;x++) 
    	{
    		cout<<input.x<<endl;
     } 
    
    	cout<<"The new account has been saved\n";
    		cout<<"---------   *   ____________    *   ---------\n";
    	
    	main();
    				
    	}
      if(input.choice==2)
      {
    	  cout<<"Please Type the name of the account, note .txt must be included:\n";
    		  cin.getline( input.opn, 90);
    	  ifstream b_file(input.opn,  ios::nocreate);
    	  cout<<"\n";
    	  for(int x=0;x<101;x++);
    	{
    		cout<<input.x<<endl;
     } 
    	  cout<<input.opn <<"Opened, the data stored is:\n";
    	  b_file.get(input.data, 1000);
    	  cout<<input.data;
    	  b_file.close();
      }
    
    
    if(input.choice==3)
    {
    	cout<<"Information about the programmer:\n";
    	cout<<"---------------------------------\n";
    	cout<<"I am a beginner in programming totaly new to it, I found it alot injoyable and chalenging I was in Webdesigning only, but now I'm trying to get my interests to cover every single bit in the computers, thanks.\n";
    	cout<<"OK, now here is my profile:\n";
    	cout<<"Name:  Shady M. Philip\n";
    	cout<<"Birthdate: 25/1/1988\n";
    	cout<<"Interests:\n";
    	cout<<"		* Computers and Internet.\n";
    	cout<<"		* Programming and webdesign.\n";
    	cout<<"		* Goin' out.\n";
    	cout<<"		* Movies.\n";
    	cout<<"		* Songs.\n";
    	cout<<"		* Chalenges.\n";
    	cout<<"		* Having alot of friends.\n";
    
    	cout<<"Sorry there's not any way to contact me except if you find this program in a website you can post to it and contact me through there, Have fun.\n";
    
    }
    
    if(input.choice==4)
    {
    	quest();
    }
    	}
    	
    	
    int quest()
    {
    	database input
    	cout<<"Are you sure you want to Quit? y or n";
    	cin>>input.qui;
    
    	if(input.qui=="y")
    	
    	{
    		cout<<"ByeBye";
    		for(int input.c=0;x<11;x++) 
    	{
    		cout<<input.x;
     } 
    return 0;
    	}
    	if(input.qui=="n")
    	{
    		main();
    	}
    	else
    	{
    		cout<<"This is not an option\n";
    		quest();
    			}
    
    	}
    
    [
    Last edited by sweet2awy; 07-25-2003 at 12:27 PM.
    me

  8. #8
    Amy amirahasanen1's Avatar
    Join Date
    Jul 2003
    Posts
    49

    Arrow

    Note: I'm still a C++ beginner, I've just read the first 10 lessons of the tutorial in the www.cprogramming.com website, I've fixed the errors in a beginners way, but the program is working now..

    Hey Sweet2awy..

    1-) The quest error:

    before you declare:

    Code:
    int main()
    {
    code;
    code;
    code;
    }
    you had to declare the quest(); but not define it, exactly as u do with functions:

    int quest();

    and you would define it after ending the main() as you've done, so that it would be like that:

    Code:
    #include<fstream.h>
    #include<iostream.h>
    #include<conio.h>
    #include<string.h>
    struct database
    {
    code;
    code;
    code;
    };
    int quest();
    int main()
    {
    code;
    code;
    code;
    }
    int quest()
    {
    code;
    code;
    code;
    }

    -------------------------------------------------------------------------


    2-) quit didn't work for a problem, I've fixed it also,
    you wrote:

    Code:
    if(input.qui="y")
    {
    code;
    }
    if(input.qui="y")
    {
    code;
    }
    else
    {
    code;
    }

    that way can't work with char(s), just works with int(s) & may b float(s) i guess,
    so u should hav written as we've learned in the strings lesson, u should use the way of comparing strings as follows:

    Code:
    if(!strcmpi("y", input.qui))
    {
    code;
    }
    else if(!strcmpi("n", input.qui))
    {
    code;
    }
    else
    {
    code;
    }

    -------------------------------------------------------------------------


    3-) another error was that:

    Code:
    for(int input.c=0;c<11;c++)
    {
     cout<<c<<endl;
    }
    that will make confusion, cos now when you say input.c it's okay, but when u say c<11 it's not right, cos it's undefined (c) is undefined while (input.c) is, & if u converted it to input.c<11, I guess we won't be able to convert the third attribute to input.c++
    so I've removed both of the int x; & int c; from the struct database, and I've declared them normally in int main()


    -------------------------------------------------------------------------


    4-) another error was that (not completely an error):

    Code:
    a_file<<"Full name: "<<input.fstname<<"\n"
    a_file<<"Birthdate: "<<input.bd<<"\n"
    a_file<<"Amout of money: "<<input.mon;
    which would put every detail in a single line, that will not make it able for the option "2" (open an existant account) to view the whole file as it only takes the first line, so I've put'em all in one line that way:

    Code:
    a_file<<"Full Name: "<<input.fstname<<" _ "<<"Birthdate: "<<input.bd<<" _ "<<"Amout of money: "<<input.mon;
    -------------------------------------------------------------------------


    5-) Another thing was that u forgot to recall the menu main(); after ending some commands, so the program was ending itself after viewing an existant account and in other ways..
    It ain't illegal until you get caught..

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21