Jede andere Option funktioniert außer Option 1. Nachdem ein Benutzer den Namen und den Kontotyp eingegeben hat. Es tritt in eine Endlosschleife ein. Wie stelle ich meine Do-While-Schleife ein, um dieses Verhalten zu beheben? Kann mir bitte jemand helfen, dieses Problem zu beheben?Wie Sie eine do ... while-Schleife mehr als einmal in Schleife halten, während die Bedingung auf "true" gesetzt ist
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;
#include<iostream>
#include<string>
#include<iomanip>
#include<cstdlib>
using namespace std;
class Bank{
//data members
private:
string customer_name;
double account_number;
string type_of_account;
double account_balance;
double balance;
//function declaration
public:
void assignInitialValue(void);
void deposit();
void makeWithdrawal();
void displayNameAndBalance();
void displayDetails();
};
//function definitions
void Bank::assignInitialValue(void){
cout<<"Welcome to Our Bank."<<endl;
cout<<"To open an Account with us,please supply the following details"<<endl;
cout<<"Enter your name in full"<<endl;
cin>>customer_name;
cout<<"Choose an Account type"<<endl;
cin>>type_of_account;
cout<<"Enter your Account Number"<<endl;
cin>>account_number;
cout<<"Enter an Amount you will like to open this account with"<<endl;
cin>>account_balance;
cout<<"Thank you for banking with us";
}
void Bank::deposit(void){
scout<<"Enter the amount you want to deposit"<<endl;
double deposit_amount = 0.0;
cin>>deposit_amount;
account_balance = account_balance + deposit_amount;
cout<<"Your new balance is now:"<<account_balance;
balance = account_balance;
}
void Bank::makeWithdrawal(void){
int withdrawal_amount;
cout<<"\nBalance Amount = "<<balance;
cout<<"\nPlease Enter the Amount you want to withdraw:-";
cin>>withdrawal_amount;
if(!(withdrawal_amount > balance))
balance=balance-withdrawal_amount;
else
{
cout<<"Insufficient Balance";
}
cout<<"Your Available Balance is:"<<balance;
}
void Bank::displayDetails(void)
{
cout<<endl<<endl<<endl;
cout<<setw(50)<<"CUSTOMER DETAILS"<<endl;
cout<<setw(50)<<"Customer Name "<<customer_name<<endl;
cout<<setw(50)<<"Account Number."<<account_number<<endl;
cout<<setw(50)<<"Account Type"<<type_of_account<<endl;
cout<<setw(50)<<"Balance"<<balance<<endl;
}
int main()
{
Bank app;
int Activity_code;
do
{
cout<<"\n\nAvailable Transactions\n\n";
cout<<"1) To create Account with us press 1\n";
cout<<"2) To make deposit press 2\n";
cout<<"3) To make Withdrawal press 3\n";
cout<<"4) To Display All Details press 4\n";
cout<<"5) EXIT\n";
cout<<"Please enter an Activity choice :-";
cin>>Activity_code;
switch(Activity_code)
{
case 1: app.assignInitialValue();
break;
case 2: app.deposit();
break;
case 3: app.makeWithdrawal();
break;
case 4: app.displayDetails();
break;
case 5: goto terminate;
}
}while(true);
terminate:
return 0;
}
Können Sie bitte angeben, was das erwartete Verhalten ist? –
Ernsthaft, niemand wird * jemals * deinen Code lesen wollen, wenn du ihn nicht nachvollziehbar formatieren kannst. Habe es diesmal für dich erledigt, aber bitte, nimm dir Zeit, um dir die Zeit zu nehmen. Sie denken vielleicht nicht, dass es wichtig ist, aber wenn Sie über einhunderttausend Zeilen über ein Dutzend Quelldateien hinweg strömen, macht das einen Unterschied. – WhozCraig
Bitte geben Sie den Bereich an, in dem Sie kollabiert sind. –