The cases you have for 'a' and 'A', 's' and 'S', 'f' and 'F' do not have much in common. So I do not think you can write one function to incorporate all of their functionality within one function, then based on a parameter do an action. You can, however, make your code more readable by enclosing all of the 3 different cases in one function that does not take a parameter and return void:
void Case_s_S()
{
int count = 0;
inFile.open("tasks.txt");
while (inFile)
{
inFile.getline(track[count].course, MAXLINE, ';');
inFile.getline(track[count].desc, MAXLINE, ';');
inFile.getline(track[count].date, MAXLINE, '\n');
if (inFile)
{
cout << track[count].course << ";" << track[count].desc << ";"
<< track[count].date << "\n";
count++;
}
}
inFile.close();
cin.clear();
}
One more suggestion I can give you, so you keep your "main" more neat, is to make use of function pointers. You can lookup std::function which is defined in . What you can do is have a map of chars and std::functions, which will look like std::map>. Then you can assign keys of 'a' and 'A' to point to value of function Case_a_A and so on and so forth. That way when the user presses the key, you just go to that key and call its value, which will be the function.