Question

In: Computer Science

I am getting 7 errors can someone fix and explain what I did wrong. My code...

I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom.

Welcome to the DeVry Bank Automated Teller Machine

Check balance

Make withdrawal

Make deposit

View account information

View statement

View bank information

Exit

   

     The result of choosing #1 will be the following:
          Current balance is: $2439.45

    The result of choosing #2 will be the following:
          How much would you like to withdraw? $200.50

     The result of choosing #3 will be the following:
          How much would you like to deposit? $177.32     

     The result of choosing #4 will be the following:

          Name: (Student’s first and last name goes here)

          Account Number: 1234554321

    The result of choosing #5 will be the following:
          01/01/11 - McDonald’s - $6.27

          01/15/11 - Kwik Trip - $34.93

          02/28/11 - Target - $124.21

     The result of choosing #6 will be the following:
          Devry Bank, established 2011

          (123) 456-7890

          12345 1st St.

          Someplace, NJ 12345

     The result of choosing #7 will be the following:
          *Exit the program - terminate console application.

You will create a Menu Builder class (for menu applications), a Test Menu class (for Main), and a MenuBuilder.h for a total of three files as a demonstration of understanding, creating, and using classes.

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


class MenuBuilder
{
private:
   double balance; // private data member
public:

   MenuBuilder();
   ~MenuBuilder();
   // methods
   void buildMenu();
   void processInput(int);
};

#include "MenuBuilder.h"

// constructor
MenuBuilder::MenuBuilder(void);
{
   balance = 2439.45;
}

MenuBuilder::MenuBuilder()
{
}

// deconstructor
MenuBuilder::~MenuBuilder(void)
{
}

// output the menu
void MenuBuilder::buildMenu()
{
   cout << endl;
   cout << " Welcome to the DeVry Bank Automated Teller Machine" << endl << endl;
   cout << " 1. Check Balance " << endl;
   cout << " 2. Make Withdrawl " << endl;
   cout << " 3. Make Deposit " << endl;
   cout << " 4. View Account Information " << endl;
   cout << " 5. View Statement " << endl;
   cout << " 6. View Bank Information " << endl;
   cout << " 7. Exit " << endl;
   cout << " Enter Selection: " << endl;

}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
   double withdrawl;
   double deposit;
   double balance;

   switch (choice)
   {
   case 1: cout << " Your current balance is: " << balance << endl; break;
   case 2: cout << " How much would you like to withdraw? " << endl;
       cin >> withdrawl;
       if (balance > withdrawl && withdrawl > 0)
           balance = balance - withdrawl;
       cout << " Your balance after withdrawl is : " << balance << endl;
       else
           cout << " Invalid withdrawl!" << endl;
       break;
   case 3: cout << " How much would you like to deposit? " << deposit << endl;
       cin >> deposit;
       if (deposit > 0)
           balance = balance + deposit;
       cout << " You balance after deposit is: " << balance << endl;
       else
           cout << " Invalid deposit! " << endl;
       break;
   case 4: cout << " Account information : " << endl;
       cout << " Name: Alicia Shorts" << endl;
       cout << " Account Number: 246743522829" << endl;
       break;
   case 5: cout << " 01/01/11 - McDonald's - $6.27 " << endl;
       cout << " 01/15/11- Kwik Trip - $34.93" << endl;
       cout << " 02/28/11- Target-$124.21" << endl;
       break;
   case 6: cout << " DeVry Bank, established 2011" << endl;
       cout << " (123) 456-7890" << endl;
       cout << " 12345 1st St." << endl;
       cout << " Someplace, NJ 12345" << endl;
       break;
   case 7: cout << "Invalid selection" << endl; break;
   default: cout << " Invalid selection" << endl; break;

   }// switch


}


#include "MenuBuilder.h"

int main()
{
   // declare variables
   MenuBuilder transaction;
   int choice = 0;
   while (choice != 7)
   {
       transaction.buildMenu();
       cin >> choice;
       transaction.processInput(choice);
   }

Solutions

Expert Solution

The errors are mainly because of improper using of if-else blocks in switch statement.

Working Code:

File: main.cpp

#include "MenuBuilder.h"

int main()
{
    // declare variables
    MenuBuilder transaction;
    int choice = 0;
    while (choice != 7)
    {
        transaction.buildMenu();
        cin >> choice;
        transaction.processInput(choice);
    }
}

File: MenuBuilder.h

#ifndef MENUBUILDER_H_INCLUDED
#define MENUBUILDER_H_INCLUDED

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


class MenuBuilder
{
private:
    double balance; // private data member
public:
    MenuBuilder();
    ~MenuBuilder();
    // methods
    void buildMenu();
    void processInput(int);
};

#endif // MENUBUILDER_H_INCLUDED

File: MenuBuilder.cpp

#include "MenuBuilder.h"

// constructor
MenuBuilder::MenuBuilder(void)
{
    balance = 2439.45;
}

// destructor
MenuBuilder::~MenuBuilder(void)
{
}

// output the menu
void MenuBuilder::buildMenu()
{
    cout << endl;
    cout << "      Welcome to the DeVry Bank Automated Teller Machine" << endl << endl;
    cout << " 1.   Check Balance " << endl;
    cout << " 2.   Make Withdrawl " << endl;
    cout << " 3.   Make Deposit " << endl;
    cout << " 4.   View Account Information " << endl;
    cout << " 5.   View Statement " << endl;
    cout << " 6.   View Bank Information " << endl;
    cout << " 7.   Exit " << endl;
    cout << "      Enter Selection: ";

}
// Process user's choice
void MenuBuilder::processInput(int choice)
{
    double withdrawl;
    double deposit;

    switch (choice)
    {
        case 1: cout << " Your current balance is: $" << balance << endl; break;

        case 2: cout << " How much would you like to withdraw? $";
                cin >> withdrawl;
                if (balance > withdrawl && withdrawl > 0)
                {
                    balance = balance - withdrawl;
                    cout << " Your balance after withdrawl is : $" << balance << endl;
                }
                else
                {
                    cout << " Invalid withdrawl!" << endl;
                }
                break;

        case 3: cout << " How much would you like to deposit? $";
                cin >> deposit;

                if (deposit > 0)
                {
                    balance = balance + deposit;
                    cout << " You balance after deposit is: $" << balance << endl;
                }
                else
                {
                    cout << " Invalid deposit! " << endl;
                }
                break;

        case 4: cout << " Account information : " << endl;
                cout << " Name: Alicia Shorts" << endl;
                cout << " Account Number: 246743522829" << endl;
                break;

        case 5: cout << " 01/01/11 - McDonald's - $6.27 " << endl;
                cout << " 01/15/11- Kwik Trip - $34.93" << endl;
                cout << " 02/28/11- Target-$124.21" << endl;
                break;

        case 6: cout << " DeVry Bank, established 2011" << endl;
                cout << " (123) 456-7890" << endl;
                cout << " 12345 1st St." << endl;
                cout << " Someplace, NJ 12345" << endl;
                break;

        case 7: exit(0);

        default: cout << " Invalid selection" << endl; break;
    }// switch
}

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

Sample Output:


Related Solutions

Okay, can someone please tell me what I am doing wrong?? I will show the code...
Okay, can someone please tell me what I am doing wrong?? I will show the code I submitted for the assignment. However, according to my instructor I did it incorrectly but I am not understanding why. I will show the instructor's comment after providing my original code for the assignment. Thank you in advance. * * * * * HourlyTest Class * * * * * import java.util.Scanner; public class HourlyTest {    public static void main(String[] args)     {        ...
Can someone please tell me why I am getting errors. I declared the map and it's...
Can someone please tell me why I am getting errors. I declared the map and it's values like instructed but it's telling me I'm wrong. #include <iostream> #include <stdio.h> #include <time.h> #include <chrono> #include <string> #include <cctype> #include <set> #include <map> #include "d_state.h" using namespace std; int main() { string name; map<string,string> s; map<string,string>::iterator it; s[“Maryland”] = "Salisbury"; s[“Arizona”] = "Phoenix"; s[“Florida”] = "Orlando"; s[“Califonia”] = "Sacramento"; s[“Virginia”] = "Richmond"; cout << "Enter a state:" << endl; cin >> name;...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell...
Please see if you can correct my code. I am getting an ReferenceError in Windows Powershell that says payment is undefined. I am trying to create a main.js file that imports the function from the hr.js file; call the function passing the necessary arguments and log the result to the console. main.js var Dev = require("./hr.js") const { add } = require("./hr.js") var dev_type = 1; var hr = 40; console.log("your weekly payment is " + payment(dev_type, hr)) dev_type =...
I'm getting an error with my code on my EvenDemo class. I am supposed to have...
I'm getting an error with my code on my EvenDemo class. I am supposed to have two classes, Event and Event Demo. Below is my code.  What is a better way for me to write this? //******************************************************** // Event Class code //******************************************************** package java1; import java.util.Scanner; public class Event {    public final static double lowerPricePerGuest = 32.00;    public final static double higherPricePerGuest = 35.00;    public final static int cutOffValue = 50;    public boolean largeEvent;    private String...
Develop the following code for quiz (i am getting some errors)in python in such a manner...
Develop the following code for quiz (i am getting some errors)in python in such a manner that it shoulde be having extra 3 attempts(for wrong answrs) for all questions if the user entered wrong answer · for ex: If the user entered correct answer for first question #then 3 attempts will be carried to next questions. If the user entered 3 times wrong answer in 1st question itself means it sholud display as no more attempts and you got o...
Can you please see what I have done wrong with my program code and explain, This...
Can you please see what I have done wrong with my program code and explain, This python program is a guess my number program. I can not figure out what I have done wrong. When you enter a letter into the program, its supposed to say "Numbers Only" as a response. I can not seem to figure it out.. instead of an error message. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if...
can someone tell me if i am wrong on any of these???? THANKS In order to...
can someone tell me if i am wrong on any of these???? THANKS In order to be able to deliver an effective persuasive speech, you need to be able to detect fallacies in your own as well as others’ speeches. The following statements of reasoning are all examples of the following fallacies: Hasty generalization, mistaken cause, invalid analogy, red herring, Ad hominem, false dilemma, bandwagon or slippery slope. 1. __________bandwagon fallacy_______ I don’t see any reason to wear a helmet...
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
Can someone explain in detail how to solve the below indefinite integral? I am getting really...
Can someone explain in detail how to solve the below indefinite integral? I am getting really confused when it comes to the U-substitution part and do not understand how 9 ends up in the denominator. I know the correct answer is [-2(ln3x+1)-3x]/9 + C, but I do not know how to get there. ∫(2x)/(3x+1) dx
My code does not compile, I am using vim on terminal and got several compiling errors...
My code does not compile, I am using vim on terminal and got several compiling errors this is C++ language I need help fixing my code below is the example expected run and my code. Example run (User inputs are highlighted): Enter your monthly salary: 5000 Enter number of months you worked in the past year: 10 Enter the cost of the car: 36000 Enter number of cars you’ve sold in the past year: 30 Enter number of misconducts observed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT