GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 26-Jan-2007, 12:23
balletdiva37 balletdiva37 is offline
New Member
 
Join Date: Jan 2007
Posts: 5
balletdiva37 is on a distinguished road

Maintaining a checking and savings account through C++


I could use help on maintaing a checking and savings account. I am very new to C++ and any help that could be made would be extremely appreciated. This program would need to include loop, switch, if/else,then. If anyone could help with this I would be forever grateful!!
  #2  
Old 26-Jan-2007, 13:49
balletdiva37 balletdiva37 is offline
New Member
 
Join Date: Jan 2007
Posts: 5
balletdiva37 is on a distinguished road

Re: Maintaining a checking and savings account through C++


I tried working on this but I cannot get it to completely work. Does anyone know how I could possibly add a loop or an if/else/then structure to this it is a requirement to have it in my program. I could really use some pointers if anyone would be willing to look at this. Thank you in advance.

CPP / C++ / C Code:
# include<iostream.h>
# include<conio.h>
# include<iomanip.h>

class bank
	{
	char name[20];
	int acno;
	float balance;
	public:
	void init();
	void deposit();
	void withdraw();
	void disp_det();
	};
	
void bank :: init()
{
cout<<"New Account";
cout<<"Enter the Name of the depositor : ";
cin.get(name,19);
cout<<"Enter the Account Number : ";
cin>>acno;
cout<<"Enter the Amount to Deposit : ";
cin >>balance;
}
void bank :: deposit()
{
float more;
cout <<"Depositing";
cout<<"Enter the amount to deposit : ";
cin>>more;
balance+=more;
}
void bank :: withdraw()
{
float amt;
cout<<"Withdrwal";
cout<<"Enter the amount to withdraw : ";
cin>>amt;
balance-=amt;
}
void bank :: disp_det()
{
cout<<"Account Details";
cout<<"Name of the depositor : "<<name<<endl;
cout<<"Balance               : $"<<balance<<endl;
}
void main(void)
{
bank obj;
int choice  =1;
while (choice != 0 )
{
cout<<" Enter 0 to exit";
cout<<"1. Initialize a new acc.";
cout<<"2. Deposit";
cout <<"3.Withdraw";
cin>>choice;
switch(choice)
{
	case 0 :obj.disp_det();
		cout<<"EXITING PROGRAM.";
		break;
	case 1 : obj.init();
		break;
	case 2: obj.deposit();
		break;
	case 3 : obj.withdraw();
		break;
	default: 
 cout<<"Illegal Option"<<endl;
}
}
getch();
}
  #3  
Old 26-Jan-2007, 15:13
Sokar Sokar is offline
Member
 
Join Date: May 2005
Posts: 243
Sokar has a spectacular aura aboutSokar has a spectacular aura about

Re: Maintaining a checking and savings account through C++


Quote:
Originally Posted by balletdiva37
I tried working on this but I cannot get it to completely work. Does anyone know how I could possibly add a loop or an if/else/then structure to this it is a requirement to have it in my program. I could really use some pointers if anyone would be willing to look at this. Thank you in advance.
A loop where? What kind of loop?
A if/else where? ...
  #4  
Old 26-Jan-2007, 15:28
balletdiva37 balletdiva37 is offline
New Member
 
Join Date: Jan 2007
Posts: 5
balletdiva37 is on a distinguished road

Re: Maintaining a checking and savings account through C++


I wanted to include something like this in there but I can't figure out how I would add it and still have it work.

CPP / C++ / C Code:
{cout <<"How much do you want to deposit to open the account?";
cin>>amount_to_deposit;

if (amount_to_deposit < 1000.00)
{
   if (amount_to_deposit < 100.00)
   {cout <<"You should consider a EconoCheck account.\n";}
   else
   {cout <<"You should consider the FreeCheck account.\n";}
}
else 
{cout<<"You should consider an interest-bearing account.\n";}
}
  #5  
Old 26-Jan-2007, 15:32
balletdiva37 balletdiva37 is offline
New Member
 
Join Date: Jan 2007
Posts: 5
balletdiva37 is on a distinguished road

Re: Maintaining a checking and savings account through C++


I tried adding it in this source code and came up with these errors:

45 C:\Documents and Settings\Jennifer\My Documents\bankaccount.cpp expected unqualified-id before '{' token

45 C:\Documents and Settings\Jennifer\My Documents\bankaccount.cpp expected `,' or `;' before '{' token

68 C:\Documents and Settings\Jennifer\My Documents\bankaccount.cpp `main' must return `int'

Here is the code with the if/else statement included

CPP / C++ / C Code:

# include<iostream.h>
# include<conio.h>
# include<iomanip.h>

class bank
	{
	char name[21];
	int acno;
	float balance;
	float amount_to_deposit;
	public:
	void init();
	void deposit();
	void withdraw();
	void disp_det();
	};
	
void bank :: init()
{
cout<<"New Account";
cout<<"Enter the Name of the depositor : ";
cin.get(name,20);
cout<<"Enter the Account Number : ";
cin>>acno;
cout<<"Enter the Amount to Deposit : ";
cin >>balance;
}
void bank :: deposit()
{cout <<"How much do you want to deposit to open the account?";
cin>>amount_to_deposit;

if (amount_to_deposit < 1000.00)
{
   if (amount_to_deposit < 100.00)
   {cout <<"You should consider a EconoCheck account.\n";}
   else
   {cout <<"You should consider the FreeCheck account.\n";}
}
else 
{cout<<"You should consider an interest-bearing account.\n";}
}
{
float more;
cout <<"Depositing";
cout<<"Enter the amount to deposit : ";
cin>>more;
balance+=more;
}

void bank :: withdraw()
{
float amt;
cout<<"Withdrwal";
cout<<"Enter the amount to withdraw : ";
cin>>amt;
balance-=amt;
}
void bank :: disp_det()
{
cout<<"Account Details";
cout<<"Name of the depositor : "<<name<<endl;
cout<<"Balance               : $"<<balance<<endl;
}
void main(void)
{
bank obj;
int choice  =1;
while (choice != 0 )
{
cout<<" Enter 0 to exit";
cout<<"1. Initialize a new acc.";
cout<<"2. Deposit";
cout <<"3.Withdraw";
cin>>choice;
switch(choice)
{
	case 0 :obj.disp_det();
		cout<<"EXITING PROGRAM.";
		break;
	case 1 : obj.init();
		break;
	case 2: obj.deposit();
		break;
	case 3 : obj.withdraw();
		break;
	default: 
 cout<<"Illegal Option"<<endl;
}
}
getch();
}
  #6  
Old 26-Jan-2007, 18:04
Sokar Sokar is offline
Member
 
Join Date: May 2005
Posts: 243
Sokar has a spectacular aura aboutSokar has a spectacular aura about

Re: Maintaining a checking and savings account through C++


First I would say pick a style and stay with it. I personally do not like this style. It is to easy to lose track of the "}" and "{".
CPP / C++ / C Code:
void bank :: deposit()
{cout <<"How much do you want to deposit to open the account?";
cin>>amount_to_deposit;

if (amount_to_deposit < 1000.00)
{
   if (amount_to_deposit < 100.00)
   {cout <<"You should consider a EconoCheck account.\n";}
   else
   {cout <<"You should consider the FreeCheck account.\n";}
}
else 
{cout<<"You should consider an interest-bearing account.\n";}
}
{
float more;
cout <<"Depositing";
cout<<"Enter the amount to deposit : ";
cin>>more;
balance+=more;
}

void bank :: withdraw()
{
float amt;

This is easier to follow the "}" and "{".
CPP / C++ / C Code:
void bank :: deposit()
{
	cout <<"How much do you want to deposit to open the account?";
	cin>>amount_to_deposit;

	if (amount_to_deposit < 1000.00)
	{
		if (amount_to_deposit < 100.00)
		{
			cout <<"You should consider a EconoCheck account.\n";
		}
		else
		{
			cout <<"You should consider the FreeCheck account.\n";
		}
	}
	else 
	{
		cout<<"You should consider an interest-bearing account.\n";
	}
}
{
	float more;
	cout <<"Depositing";
	cout<<"Enter the amount to deposit : ";
	cin>>more;
	balance+=more;
}

void bank :: withdraw()
{
	float amt;
	cout<<"Withdrwal";

Now you can see this seems out of place. What is it?

CPP / C++ / C Code:
		cout<<"You should consider an interest-bearing account.\n";
	}
}
//{ // <- what is all this???????
	//float more;
	//cout <<"Depositing";
	//cout<<"Enter the amount to deposit : ";
	//cin>>more;
	//balance+=more;
//}

void bank :: withdraw()
{
 
 

Recent GIDBlogHalfway done! by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 13:42.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.