0

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; }

}
2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by firstPerson
0

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?

Edited by firstPerson: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.