#include<iostream.h>
#include<conio.h>
#include <stdlib.h>
int c,p,p1,p2,p3,Strans, Ctrans;
float amount;
int Cbalance = 5000;
int Sbalance = 10000;
char print;
void transaction(){
clrscr();
cout<<"Choose your transaction:";
cout<<"\n\n\n\t\t(1) Balance Inquiry\t\t(2) Withdrawal";
cout<<"\n\nSelect an Option: ";
cin>>p1;
//BALANCE INQUIRY
if(p1==1){
clrscr();
cout<<"\n\n\n\t\t\t(1) Current\t\t(2) Savings";
cout<<"\n\nSelect an Option: ";
cin>>p2;
//Balance Inquiry CURRENT
if(p2==1){
clrscr();
cout<<"\n\n\n\t\t\t Print Receipt?: ";
cout<<"\n\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\nChoose Option: ";
cin>>print;
clrscr();
cout<<"\n\n\n\t\t\t Your balance is: "<<Cbalance;
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Ctrans;
if(Ctrans==1){
transaction();
}
if(Ctrans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t\t\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
//Balance Inquiry SAVINGS
else if(p2==2){
clrscr();
cout<<"\n\n\n\t\t\t Print Receipt?: ";
cout<<"\n\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\nChoose Option (1 or 2): ";
cin>>print;
clrscr();
cout<<"\n\n\n\t\t\t Your balance is: "<<Sbalance;
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Strans;
if(Strans==1){
transaction();
}
if(Strans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t\t\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
//WITHDRAWAL
else if(p1==2){
clrscr();
cout<<"\n\n\n\t\t\t(1) Current\t\t(2) Savings";
cout<<"\n\nSelect an Option: ";
cin>>p3;
//Withdrawal CURRENT
if(p3==1){
clrscr();
cout<<"\n\n\n\t\t\t\tEnter Amount: ";
cin>>amount;
if(amount <= 0){
clrscr();
cout << "\n\n\n\t\t\t Invlaid Amount.";
cout<<"\n\n\t\t\t Please get your card.";
}
if(amount > 0&&amount < 100){
clrscr();
cout<<"\n\n\n\t\t\t Minimum amount is 100";
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Ctrans;
if(Ctrans==1){
transaction();
}
if(Ctrans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
if(amount>Cbalance){
clrscr();
cout<<"\n\n\n\t\t\t\tInsuficient funds!";
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Ctrans;
if(Ctrans==1){
transaction();
}
if(Ctrans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
if(amount<=Cbalance&&amount>=100){
clrscr();
cout<<"\n\n\n\n\t\t\t\tBalance: "<<Cbalance - amount;
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Strans;
if(Strans==1){
transaction();
}
if(Strans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t Please get your card and count your money before leaving.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
}
//Withdrawal SAVINGS
else if(p3==2){
clrscr();
cout<<"\n\n\n\t\t\t\tEnter Amount: ";
cin>>amount;
if(amount <= 0){
clrscr();
cout << "\n\n\n\t\t\t Invalid Amount.";
cout<<"\n\n\t\t\t Please get your card.";
}
if(amount > 0&&amount < 100){
clrscr();
cout<<"\n\n\n\t\t\t Minimum amount is 100";
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Strans;
if(Strans==1){
transaction();
}
if(Strans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
if(amount>Sbalance){
clrscr();
cout<<"\n\n\n\t\t\t\tInsuficient funds!";
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Strans;
if(Strans==1){
transaction();
}
if(Strans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
if(amount<=Sbalance&&amount>=100){
clrscr();
cout<<"\n\n\n\n\t\t\t\tBalance: "<<Sbalance - amount;
cout<<"\n\n\n\n\n\t\t Do you want to have another transaction?";
cout<<"\n\n\t\t\t (1) Yes (2) No";
cout<<"\n\n\nChoose Option (1 or 2): ";
cin>>Strans;
if(Strans==1){
transaction();
}
if(Strans==2){
clrscr();
cout<<"\n\n\n\n\t\t\tThank you for banking with us.";
cout<<"\n\t Please get your card and count your money before leaving.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
void main(){
clrscr();
cout<<"\n\n\t\t -----------------------------------------\n";
cout<<"\t\t WELCOME TO BANK OF THE PHILIPPINE ISLANDS\n ";
cout<<"\t\t -----------------------------------------\n";
cout<<"\n\n\t\t (1) Continue\t\t(2) Exit";
cout<<"\n\n\n\nSelect an Option (1 or 2): ";
cin>>c;
//CONTINUE
if(c==1){
clrscr();
cout<<"\n\n\n\t\t\t\tEnter your PIN: ";
cin>>p;
//TRANSACTION
if(p==1234){
transaction();
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\t Wrong PIN!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
//EXIT
else if(c==2){
clrscr();
cout<<"\n\n\t\t\tThank you for banking with us.";
cout<<"\n\n\t\t\t Please get your card.";
}
else{
clrscr();
cout<<"\n\n\n\t\t\t\tInvalid Input!";
cout<<"\n\n\t\t\t Please get your card.";
}
}
getch();
我在C ++上为我朋友的学校项目制作ATM界面。如何将PIN码更改为星号“*”?附:该 引脚号码在MAIN中。谢谢:D
我在C ++上为我朋友的学校项目制作ATM界面。如何将PIN码更改为星号“*”?附:该 引脚号码在MAIN中。谢谢:D
答案 0 :(得分:0)
您可以像这样使用getch()
:
int i=1;
cout<<"\n\n\n\t\t\t\tEnter your PIN: ";
while((p=getch()) != '\n' && p==i) {
i++;
cout<<"*";
}
if(i==5)
transaction();
else {
clrscr();
cout<<"\n\n\n\t\t\t\t Wrong PIN!";
cout<<"\n\n\t\t\t Please get your card.";
}
或者像这样:
int i=0,pin[4]={0};
cout<<"\n\n\n\t\t\t\tEnter your PIN: ";
while((pin[i]=getch()) != '\n' && i<4) {
i++;
cout<<"*";
}
if(pin[0]==1 && pin[1]==2 && pin[2]==3 && pin[3]==4)
transaction();
else {
clrscr();
cout<<"\n\n\n\t\t\t\t Wrong PIN!";
cout<<"\n\n\t\t\t Please get your card.";
}