Note - I'm still learning c++... so there could be better ways of coding this. Try not to introduce new concepts - this will only aid in confusing me more, but please be more than welcomed to tell that i'm using something incorrectly.

// Classes - Using class to design a mock bank account
//
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;

#include "Saving.h"

int main (int nNumberofArgs, char* pszArgs[])
{
 cout << "Enter 1 to create an account : ";
 int nEntered;
 cin >> nEntered;
 for(;;)
 {
 if( nEntered == 1)
 {
  BankAccount s;
  cout << " Bank account created\n If you would like to make a deposit press 1";
  break;
 }
 else
 {
  cout << "You didn't enter a vaild number";
 }
 }
 int nAnother;

 for(;;)
 {
 if(nAnother || nEntered == 2)
 { cout << "How much do want to deposit : ";
   int ndeposit;
   cin >> ndeposit;
   s. deposit(ndeposit)
   break;
 }
 else
 {
   cout << "You didn't enter a vaild number";
 }
system("PAUSE");
return 0;
 }
}

Header file:

class BankAccount
{
public:
unsigned accountNumber;
double balance;

double deposit(int money)
{ balance += money;
 cout << "Your current balance is : " << balance << endl;

 return balance; }

}

Recommended Answers

All 2 Replies

bah!
just noticed some errors *is sleepy*

This code :

cout << "Enter 1 to create an account : ";
 int nEntered;
 cin >> nEntered;
 for(;;)
 {
 if( nEntered == 1)
 {
  BankAccount s;
  cout << " Bank account created\n If you would like to make a deposit press 1";
  break;
 }
 else
 {
  cout << "You didn't enter a vaild number";
 }
 }

is bad already. Try something like this :

bool shouldCreateAccount = true;
cout << "Would you like to create an account<1 = yes, 0 = no >";
cin >> shouldCreateAccount;
if(!shouldCreateAccount) return 0;
else { createAccount(); }
//...

The same with the rest. Why are you using infinite for loops?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.