我需要让这个程序接受用户输入,在 void get_option 中验证它(确认是否为数字,大写或小写)。如果其中任何一个为真,则调用函数字符串测试以输出相关语句。
void get_option 没有正确循环(直到正确输入)并且我对如何将结果输入函数 string_test 感到困惑?有人可以突出我错在哪里吗?谢谢
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
void get_option(char&);
string test(char&);
int main()
{
char option;
cout << "Please enter an alphanumeric character: " << endl;
cin >> option;
get_option(option);
test(option);
}
//string test takes output if void get_option is true & outputs relevant statement
string test(char &y)
{
if (isupper(y)) return "An upper case letter is entered!";
if (islower(y)) return "A lower case letter is entered!";
return "A digit is entered!";
}
//void get_option takes char output and checks if digit, lower or upper
//it should loop until a valid input is entered
void get_option(char &x)
{
while (!(isdigit(x)||islower(x)||isupper(x)))
{
cout << "Please enter an alphanumeric character: " << "\n";
cin >> x;
}
return;
}