Home > Back-end >  Solving, c language program
Solving, c language program

Time:09-19

* please select menu: balance query (1) and deposits (2), (3) withdrawal, close (3) :
1The balance remaining 10000 yuan
* please select menu: balance query (1) and deposits (2), (3) withdrawal, close (3) : 2
Deposit amount: 5000
The balance remaining: 15000 yuan
* please select menu: balance query (1) and deposits (2), (3) withdrawal, closed (3) : 3
The amount: 25000
Insufficient
* please select menu: balance query (1) and deposits (2), (3) withdrawal, closed (3) : 3
The amount: 3000
The balance remaining: 12000 yuan
* please select menu: balance query (1) and deposits (2), (3) withdrawal, closed (3) : 4
The program to shut down

CodePudding user response:

 switch (query) 
{
Case 1

Case 2

Case 3
//a framework about the menu, just to fill the content inside the
}

CodePudding user response:

Logic is simple, read more smoothly, but the code is verbose, can write their own functions to cut code amount
 # include 
using namespace std;
Int main () {
Int the pre=0;//the amount, the default is 0, to read and write files or other way default
Int c;//is
Int TMP.
While (1) {
Cout<& lt;" * please select menu: balance query (1) and deposits (2), (3) withdrawal, closed (4) : ";
Cin> c;
while(! ((c>=1) & amp; & (c<=4))) {//cross-border judgment
Cout<& lt;" Input error! Please input again: ";
Cin> c;
}
The switch (c) {
Case 1:
Cout<& lt;" The balance remaining "& lt; break;
Case 2:
Cout<& lt;" Deposit: ";
Cin> TMP.//input amount of deposit
The pre +=TMP;
Cout<& lt;" The balance remaining "& lt; break;
Case 3:
Cout<& lt;" Withdrawal amount: ";
Cin> TMP.
If (tmp> The pre) cout<& lt;" Lack of balance & lt;" The else {
The pre -=TMP;
Cout<& lt;" The balance remaining: "& lt; }
break;
Case 4:
return 0;
}
}
}

CodePudding user response:

 # include 
using namespace std;
Int main () {
Int the pre=0;//the amount, the default is 0, to read and write files or other way default
Int c;//is
Int TMP.
While (1) {
Cout<& lt;" * please select menu: balance query (1) and deposits (2), (3) withdrawal, closed (4) : ";
Cin> c;
while(! ((c>=1) & amp; & (c<=4))) {//cross-border judgment
Cout<& lt;" Input error! Please input again: ";
Cin> c;
}
The switch (c) {
Case 1:
Cout<& lt;" The balance remaining "& lt; break;
Case 2:
Cout<& lt;" Deposit: ";
Cin> TMP.//input amount of deposit
The pre +=TMP;
Cout<& lt;" The balance remaining "& lt; break;
Case 3:
Cout<& lt;" Withdrawal amount: ";
Cin> TMP.
If (tmp> The pre) cout<& lt;" Lack of balance & lt;" The else {
The pre -=TMP;
Cout<& lt;" The balance remaining: "& lt; }
break;
Case 4:
Cout<& lt;" A program shut down
"return 0;
}
}
}