Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How can I alter the code to show me a list of all the deposits I input into case

ID: 3865772 • Letter: H

Question

How can I alter the code to show me a list of all the deposits I input into case 1?

#include <cstdlib>
#include <iostream>

using namespace std;

int Deposit (int amount, int currentBalance);
int Withdrawal (int amount, int currentBalance);
void viewBalance (int currentBalance);

int main(int argc, char** argv) {
  
//variables
int currentBalance = 1000; // beginning balance for checking account
int amount = 0;
int answer = 0;
bool notComplete = true;
  
while (notComplete){
cout << "--Would you like to make a withdrawal, deposit or a view of balance-- ";
cout << "Submit 1 for Deposit / 2 for withdrawal / 3 for view balance / 4 for end of session ";
cin >> answer;
  
switch (answer)
{

case 1:
cout << "Enter the deposit amount" <<endl;
cin >> amount;
currentBalance = Deposit (amount, currentBalance);
cout << "Your deposit is: " << amount << " " << endl;
  
cout << "Your new balance is: " << currentBalance << " " <<endl;
break;
  
case 2:
cout << "Enter the withdrawal amount" <<endl;
cin >> amount;
if (amount > currentBalance)
{
cout << "Insufficient funds ";
break;
  
} // end the withdrawal amount
case 3:
viewBalance(currentBalance);
break;
  
case 4:
notComplete = false;
break;
  
default:
cout << "Not a valid input";
break;
  
}// end switch
}// end while loop
  
cout << " Thank you and and have a wonderful day! ";
system ("pause");
return 0;
}// end main

int Deposit (int amount, int currentBalance)
{
currentBalance +=amount;
return currentBalance;
  
}//end deposit

int Withdrawal(int amount, int currentBalance)
{
currentBalance -= amount;
return currentBalance;
}// end withdrawal

void viewBalance (int currentBalance)

{
cout <<" Your current balance is: " <<currentBalance << " ";
}

Explanation / Answer

// I have used the List to Store all the deposits . After every deposit it will show all the amount deposited so far

// I have corrected the withdrawal logic also

#include <cstdlib>

#include <iostream>

#include <list>

#include <iterator>

using namespace std;

int Deposit (int amount, int currentBalance);

int Withdrawal (int amount, int currentBalance);

void viewBalance (int currentBalance);

void showDeposit(list<int> deposits);

int main(int argc, char** argv) {

  

//variables

int currentBalance = 1000; // beginning balance for checking account

int amount = 0;

int answer = 0;

bool notComplete = true;

list <int> allDeposits;

  

while (notComplete){

cout << "--Would you like to make a withdrawal, deposit or a view of balance-- ";

cout << "Submit 1 for Deposit / 2 for withdrawal / 3 for view balance / 4 for end of session ";

cin >> answer;

  

switch (answer)

{

case 1:

cout << "Enter the deposit amount" <<endl;

cin >> amount;

currentBalance = Deposit (amount, currentBalance);

cout << "Your deposit is: " << amount << " " << endl;

  

cout << "Your new balance is: " << currentBalance << " " <<endl;

allDeposits.push_back(amount);

  

cout << "Your all Deposits So far is"<<endl;

showDeposit(allDeposits);

  

break;

  

case 2:

cout << "Enter the withdrawal amount" <<endl;

cin >> amount;

if (amount > currentBalance)

{

cout << "Insufficient funds ";

break;

  

} else {

currentBalance = Withdrawal(amount, currentBalance);

cout<<"Current Balance After WithDrawl " <<currentBalance<<endl;

}

break;

case 3:

viewBalance(currentBalance);

break;

  

case 4:

notComplete = false;

break;

  

default:

cout << "Not a valid input";

break;

  

}// end switch

}// end while loop

  

cout << " Thank you and and have a wonderful day! ";

system ("pause");

return 0;

}// end main

int Deposit (int amount, int currentBalance)

{

currentBalance +=amount;

return currentBalance;

  

}//end deposit

int Withdrawal(int amount, int currentBalance)

{

currentBalance -= amount;

return currentBalance;

}// end withdrawal

void viewBalance (int currentBalance)

{

cout <<" Your current balance is: " <<currentBalance << " ";

}

void showDeposit(list<int> deposits){

list <int> :: iterator it;

for(it = deposits.begin(); it != deposits.end(); ++it)

cout << ' ' << *it;

cout << ' ';

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote