所以我正在为一个作业制作一个程序,目前我正在尝试获取用户输入并尝试使其适合某种形式.
例如,用户输入格式为mm/yyyy的日期.如果用户没有以该格式键入,则只会重新提示用户.
到目前为止这是我的小循环:
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
int findSlash(char[], int);
int findLastEle(char[]);
int main() {
//variables
char expDate[7];
int expLast, expEle;
int expLen;
do{
cout << "Enter experation (form mm/yyyy): ";
cin.getline(expDate, 7);
expLen = strlen(expDate);
expEle = findSlash(expDate, expLen);
expLast = findLastEle(expDate);
}while(expEle != (expLast - 4));
return 0;
}
//findSlash function (finds slash place in array)
int findSlash(char array[], int arrayLen){
int r, dec = 0;
for(r = 0; r < arrayLen; r++){ …Run Code Online (Sandbox Code Playgroud)