Hey guys im working on a a banking program for my cpsc class and i have the code finished and i just cant get it to run, i believe my brackets are wrong somewhere but i just cant figure out which ones so if someone could juss help me out with my code, i would really appreciate it. thanx.

heres my code:

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
// Declare Variables
int withdraw;
string name;
double acctbalance, deposit;
char choices;
acctbalance = 0;
//inputs, get the name and initial balance
cout << "Enter Name: ";
cin >> name;
cout << "Please enter initial balance: ";
cin >> acctbalance;
cout << "What do you wish to do?" << endl;
cout << "D Deposit Money" << endl;
cout << "W Withdraw Money" << endl;
cout << "B Display Balance" << endl;
cout << "Q Quit" << endl;
cin >> choices;
switch (choices)
{
case 'D':
case 'd':
{
cout << "Enter amount to be deposited: "<< endl;
cout << deposit;
if (deposit > 0)
{
acctbalance = acctbalance + deposit;
if (deposit >= 1000)
cout <<"Big Money!"<<endl;
break;
}
if (deposit == 0 || deposit < 0)
{
cout <<"Amount must be > 0";
break ;
}
}
case 'B':
case 'b':
{
cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
if (acctbalance ==0)
cout <<"Big Money!"<<endl;
break;
}
case 'W':
case 'w':
{
cout<<"Please enter amount to withdraw "<<endl;
cout<<"Value must be multiple of 20"<<endl;
if (withdraw == 00)
{
cout << "Can't withdraw 0 dollars"<< endl;
break;
}
if (withdraw < 0)
{
cout<<"Must be a positive number"<<endl;
break;
}
if (withdraw > acctbalance)
{
cout<<"Can't withdraw more than balance"<<endl;
break;
}
if ((withdraw % 20) !=0)
{
cout<<"amount must be a multiple of 20"<<endl;
break;
}
else
{
acctbalance=acctbalance - withdraw;
cout<<"Here is your money. Enjoy!"<< endl;
break;
}
}

case 'Q':
case 'q':
{
cout<<"Thank for using our services have a nice day!"<<endl;
break;
}
}
}


}
while (choices ! = 'q' && choices ! = 'Q');
{
cout<<"Written by Ravi Mandair CPSC 1103 Assignment 1 Section10"<<endl;
}
return 0;
}

Recommended Answers

All 7 Replies

Try indenting/using code tags (some IDEs can even indent for you!):

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
int main()
{
    // Declare Variables
    int withdraw;
    string name;
    double acctbalance, deposit;
    char choices;
    acctbalance = 0;
    //inputs, get the name and initial balance
    cout << "Enter Name: ";
    cin >> name;
    cout << "Please enter initial balance: ";
    cin >> acctbalance;
    cout << "What do you wish to do?" << endl;
    cout << "D Deposit Money" << endl;
    cout << "W Withdraw Money" << endl;
    cout << "B Display Balance" << endl;
    cout << "Q Quit" << endl;
    cin >> choices;
    switch (choices)
    {
        case 'D':
        case 'd':
        {
            cout << "Enter amount to be deposited: "<< endl;
            cout << deposit;
            if (deposit > 0)
            {
                acctbalance = acctbalance + deposit;
                if (deposit >= 1000)
                    cout <<"Big Money!"<<endl;
                break;
            }
            if (deposit == 0 || deposit < 0)
            {
                cout <<"Amount must be > 0";
                break ;
            }
        }
        case 'B':
        case 'b':
        {
            cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
            if (acctbalance ==0)
                cout <<"Big Money!"<<endl;
            break;
        }
        case 'W':
        case 'w':
        {
            cout<<"Please enter amount to withdraw "<<endl;
            cout<<"Value must be multiple of 20"<<endl;
            if (withdraw == 00)
            {
                cout << "Can't withdraw 0 dollars"<< endl;
                break;
            }
            if (withdraw < 0)
            {
                cout<<"Must be a positive number"<<endl;
                break;
            }
            if (withdraw > acctbalance)
            {
                cout<<"Can't withdraw more than balance"<<endl;
                break;
            }
            if ((withdraw % 20) !=0)
            {
                cout<<"amount must be a multiple of 20"<<endl;
                break;
            }
            else
            {
                acctbalance=acctbalance - withdraw;
                cout<<"Here is your money. Enjoy!"<< endl;
                break;
            }
        }
 
        case 'Q':
        case 'q':
        {
            cout<<"Thank for using our services have a nice day!"<<endl;
            break;
        }
    }
}
 
}
while (choices ! = 'q' && choices ! = 'Q');
{
    cout<<"Written by Ravi Mandair CPSC 1103 Assignment 1 Section10"<<endl;
}
return 0;
       }

U wrote this code and U have bracket problem :rolleyes: ? If U want to compile this code remove two brackets in front of while loop. Your problem not ends here. Read this. There are more problems but first do this.

Here is your code corrected....

Pls work more attentively.. u didnt pass any cin statement...
while there are some errors with bracket too...

Shekhar

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

int main()
{
// Declare Variables
   int withdraw;
   string name;
   double acctbalance, deposit;
   char choices;
   acctbalance = 0;
//inputs, get the name and initial balance
          cout << "Enter Name: ";
          cin >> name;
          cout << "Please enter initial balance: ";
          cin >> acctbalance;
          do
          {
          cout<<"\n\n-------------------------------------------------\n";
          cout << "What do you wish to do?" << endl;
          cout << "D Deposit Money" << endl;
          cout << "W Withdraw Money" << endl;
          cout << "B Display Balance" << endl;
          cout << "Q Quit" << endl<<endl;cout<<"Enter selection: ";
          cin >> choices;
          switch (choices)
          {
                 case 'D':
                 case 'd':
                          {
                          cout << "Enter amount to be deposited: "<< endl;
                          cin >>deposit;
                          if (deposit > 0)
                                      {
                                      acctbalance = acctbalance + deposit;
                                      if (deposit >= 1000)
                                      cout <<"Big Money!"<<endl;
                                      break;
                                      }
                          if (deposit == 0 || deposit < 0)
                                      {
                                      cout <<"Amount must be > 0";
                                      break ;
                                      }
                          }
                 case 'B':
                 case 'b':
                          {
                          cout <<"Your current balance is $ "<<acctbalance<<'.'<<endl;
                          if (acctbalance ==0)
                                          cout <<"Big Money!"<<endl;
                          break;
                          }
                 case 'W':
                 case 'w':
                          {
                          cout<<"Please enter amount to withdraw "<<endl;
                          cout<<"Value must be multiple of 20"<<endl;
                          cin>>withdraw;
                          if (withdraw == 00)
                          {
                                       cout << "Can't withdraw 0 dollars"<< endl;
                                       break;
                          }
                          if (withdraw < 0)
                          {
                                       cout<<"Must be a positive number"<<endl;
                                       break;
                          }
                          if (withdraw > acctbalance)
                          {
                                       cout<<"Can't withdraw more than balance"<<endl;
                                       break;
                          }
                          if ((withdraw % 20) !=0)
                          {
                                       cout<<"amount must be a multiple of 20"<<endl;
                                       break;
                          }
                          else
                          {
                                       acctbalance=acctbalance - withdraw;
                                       cout<<"Here is your money. Enjoy!"<< endl;
                                       break;
                          }
                          }

                 case 'Q':
                 case 'q':
                          {
                                       cout<<"Thank for using our services have a nice day!"<<endl;
                                       break;
                          }
        }
        }while (choices != 'q' && choices != 'Q');
        
        cout<<"Written by Ravi Mandair CPSC 1103 Assignment 1 Section10"<<endl;
        return 0;
}

Here are some corrections:

// blah blah blah code

    cout << "Please enter initial balance: ";
    cin >> acctbalance;
    // add the do for the while!!!
    do
    {
        cout << "What do you wish to do?" << endl;
        cout << "D Deposit Money" << endl;
        cout << "W Withdraw Money" << endl;
        cout << "B Display Balance" << endl;
        cout << "Q Quit" << endl;
        cin >> choices;
        
        switch (choices)
        {
            case 'D':
            case 'd':
            {
                cout << "Enter amount to be deposited: "<< endl;
                //cout << deposit;  // wrong
                cin >> deposit;     // add this!!!

// blah blah blah

            case 'W':
            case 'w':
            {
                cout << "Please enter amount to withdraw " << endl;
                cout << "Value must be multiple of 20" << endl;
                cin >> withdraw;     // add this!!!

// blah blah blah

            case 'Q':
            case 'q':
            {
                cout << "Thank for using our services have a nice day!" << endl;
                break;
            }
        }
    } while (choices != 'q' && choices != 'Q');  // change ! =  to  !=

// blah blah blah

thnx a lot for all urguys help i really appreciate it!

thnx a lot for all urguys help i really appreciate it!

Yeah, where were you guys when I was learning to code? I could have partied more and let you do my home work for me, too! :rolleyes:

Yeah, where were you guys when I was learning to code? I could have partied more and let you do my home work for me, too! :rolleyes:

Bang on target my friend.

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.