if语句判断字符问题
程序代码:
#include<iostream> #include<string> using namespace std; int main(){ int i; //控制循环变量 int reNum[1]; int AnswerNum;//测验题数 *int string Answer;//测验题数 *string string strNum[100];//测验题答案 int isNumber(string str); cout << " **************测试批改系统**************" <<endl; cout << "请输入本次测验总题目数:" <<endl; tab1: cin >> Answer; reNum[1] = isNumber(Answer); if (!reNum[1]){ cout << "请确保正确的有效数字!\n" <<"请再次输入本次测试总题目数:"<<endl; goto tab1;} AnswerNum = atoi(Answer.c_str()); cout << "请输入每一题的答案、按回车键确认。" <<endl; for(i = 0;i != AnswerNum;i++){ cout << "第" <<i+1 <<"题:"; while (cin >> strNum[i]) {if(strNum[i][0] == '\n') {continue;} else {break;} } } cout<<"您已经输入完毕,待系统检测完毕...\n\n"<<endl; cout<< " Download...\n\n\n"<<endl; for(i = 0;i != AnswerNum;i++){ cout << "第" <<i+1 <<"题:"<< strNum[i] <<" "; } cout<<endl; cout<< " 系统已经录入您输入的答案,请检测。" << endl; cout<<"并且发现第"; for(i = 0;i != AnswerNum;i++){ if(strNum[i].length() > 1){ cout<< i+1<<" "; continue; }else if(strNum[i][0] == 'A' || strNum[i][0] == 'a'){ cout<< i+1<<" "; continue; }else if(strNum[i][0] == 'B' || strNum[i][0] == 'b'){ cout<< i+1<<" "; continue; }else if(strNum[i][0] == 'C' || strNum[i][0] == 'c'){ cout<< i+1<<" "; continue; }else if(strNum[i][0] == 'D' || strNum[i][0] == 'd'){ cout<< i+1<<" "; continue; } } cout<< "题有明显错误! "<<endl; cout<<endl; system("pause"); } int isNumber(string str){ int result[3]; int i = 0; int havePoint = 0; int haveReduce = 0; int isNum = 1; for(i ; i != (str.length()); i++){ if(isdigit(str[i])){ }else{ isNum = 0; } } result[0] = isNum; return result[0]; } 这个代码简单判断选择题的答案、先输入。再次判断输入的答案是不是等于ABDC时候出错、求怎么解决中间那段判断输入值是不是等于ABCD。