我真的不会问我是否真的知道答案。c++ 新手,我所知道的都在这里,它也处于试错状态,但试图赶上最后期限,这是一个家庭作业。我现在遇到的问题是,当用户输入一个字符或字符串时,我似乎找不到将其过滤掉并提示“由于输入无效而再次键入”的解决方案。.. 有任何想法吗?char 的值似乎为 0。试图键入与此相关的条件,但仍然无法正常工作。不知道该怎么办。
#include <iostream>
#include <conio.h>
using namespace std;
/*--------------------------------------------------
---------------------------------------------------------
Accounts are under pinnumbers: |
1001 increment of 1 |
Passcodes are under the codes: |
1101 increment of 1 |
|
limit of 10 as instructed. |
|
i.e : (valid pin number ) 1001 = (valid pin code) 1101 |
---------------------------------------------------------
*/
int option, pinnumber, pincode, vip[10], pc[10], money[10], accountno[10], getindex;
string name[10];
void mainmenu();
void assignaccounts();
void checkaccounts();
void start();
void options();
bool logged=false;
char a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
//<--START OF THE MAIN FUNCTION -->
main() {
assignaccounts();
start();
system("PAUSE"); //more of a getch() pero naa xa'y press any key. w/c is better!
}
//<--EOF MAIN FUNCTION-->
//<-- START OF EXTRA FUNCTION SECTION -->
//---Start of checkaccounts function --> -----------------------------
void checkaccounts() { //|
for(int x=0; x<10; x++) { //|
if(( vip[x] == pinnumber) && ( pc[x] == pincode )) { //|
logged=true; //|
getindex=x; //|
mainmenu(); //|
break; //|
} else if ((pinnumber == 'a') && (pincode == 'A' )) {
cout<<"Invalid Input, Try again."<<endl;
cin.clear();
main();
break;
} else {
;
} //|
} //|
if(!logged){ //|
cout<<"\n\t Invalid Input, Try again."<<"\n\n\t "; //|
system("PAUSE"); //|
start(); //|
} //|
//|
} //|
//end of checkaccounts function --------------------------------------
//Start of Assignaccounts function------------------------------------
void assignaccounts() { //|
for(int x=0; x<10; x++) { //|
vip[x]=1001+x; //|
pc[x]=1101+x; //|
} //|
name[0] = "John Do Doe"; //|
money[0] = 10000; //|
accountno[0] = 1; //|
//|
name[1] = "Zsaza Pa Ligid"; //|
money[1] = 20000; //|
accountno[1] = 2; //|
//|
name[2] = "Robin Pa Didit"; //|
money[2] = 30000; //|
accountno[2] = 3; //|
//|
name[3] = "lrem ipm"; //|
money[3] = 40000; //|
accountno[3] = 4; //|
//|
name[4] = "Daniel Pa Slide"; //|
money[4] = 50000; //|
accountno[4] = 5; //|
//|
name[5] = "James Bond"; //|
money[5] = 60000; //|
accountno[5] = 6; //|
//|
name[6] = "Lara Croft Llara"; //|
money[6] = 70000; //|
accountno[6] = 7; //|
//|
name[7] = "John Ziggy Pa ( GOLD MEMBER )"; //|
money[7] = 90000; //|
accountno[7] = 11; //|
//|
name[8] = "Loren Joy Chris ( GOLD MEMBER )"; //|
money[8] = 110000; //|
accountno[8] = 10; //|
//|
name[9] = "Jayson Derulo"; //|
money[9] = 120000; //|
accountno[9] = 10; //|
//|
} //|
//End of Assignaccounts function--------------------------------------
//---Start of start function --> -------------------------------------
void start() { //|
system("cls"); //|
cin.clear();
cout<<"------------------------------------------"<<endl; //|
cout<<" |** WELCOME TO CAMARILLO & ALJON ATM **|"<<endl; //|
cout<<"------------------------------------------"<<endl; //|
cout<<"\nEnter valid identification pin number (VIP): "; //|
cin>>pinnumber; //|
cout<<"\nEnter valid pincode (PC): "; //|
cin>>pincode; //|
checkaccounts(); //|
//|
} //|
//end of Start function ----------------------------------------------
//start of mainmenu function ----------------------------------------------------------------------------------
void mainmenu() { // |
int choice; // |
if(logged) { // |
while(true){ // |
system("cls"); //clearscreen // |
cout<<"Log-in successful!"<<endl; // |
cout<<"\nWelcome: "<<name[getindex]; // |
cout<<"\nAccount No.: "<<accountno[getindex]<<endl;
cout<<"\nChoose a Transaction:\n"; // |
cout<<"\n"; // |
cout<<"[1] Inquire Balance \n" // |
<<"[2] Withdraw \n" // |
<<"[3] Deposit \n" // |
<<"[4] Quit \n" // |
<<"\n"<<endl; // |
cout<<"Enter Option: "; // |
cin>>option; // |
// |
if (option == 1) { // |
cout<<"\n\tOutstanding Balance is P"<<money[getindex]<<"\n\n\t "; // |
system("PAUSE"); // |
} else if (option == 2) { // |
int co; // |
cout<<"\n\tEnter amount: "; // |
cin>>co; // |
if(co<money[getindex]){ // |
money[getindex]-=co; // |
cout<<"\n\tYour Outstanding Balance has been updated to P"<<money[getindex]<<"\n\n\t "; // |
} else { // |
cout<<"\n\t Invalid amount, Please check again."; // |
cout<<"\n\t You only have P"<<money[getindex]<<" in your account."<<"\n\n\t "; // |
} // |
system("PAUSE"); // |
} else if (option == 3) { // |
int dep; //Declaration of the cin in this case; // |
cout<<"\n\tEnter amount: "; // |
cin>>dep; // |
money[getindex]+=dep; // |
cout<<"\n\tYour Outstanding Balance has been updated to P"<<money[getindex]<<"\n\n\t "; // |
system("PAUSE"); // |
} else if (option == 4) { // |
break; // |
} else{ // |
cout << "\n\n\tInvalid Input, Try again.\n\n\t "; // |
system("PAUSE"); // |
} // |
} // |
cout<<"\n\n\t THANK YOU FOR USING OUR ATM, YOU'LL NOW EXIT THE PROGRAM."<<endl; // |
cout<<"\n\t This is intended for our project in c++ under Professor Machica."<<"\n\n\t "; // |
} // | // |
} // |
//end of mainmenu function-------------------------------------------------------------------------------------
//<-- EOF EXTRA SECTION FUNCTIONS-->