-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvalidStr.cpp
More file actions
47 lines (39 loc) · 1.13 KB
/
Copy pathvalidStr.cpp
File metadata and controls
47 lines (39 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/***************************************
Program Name: Project 1
Author: Robert Elsom
Date: 1/10/2019
Description: Checks that inputted string from the menu function
fits in the parameters of the program. If
it does, it returns the string that was tested.
**************************************/
/**********************************************
Test case 1 = starting menu prompt
to reuse: change number of menu options
update if statement to contain all options
Test case 2 = Y or N question
to reuse: no changes necessary
**********************************************/
#include <string>
#include <iostream>
#include <ctype.h>
using std::cout;
using std::cin;
using std::endl;
using std::string;
string validStr(string prompt) {
string testString;
bool validFlag = false;
string userChoice;
while (validFlag == false) {
cout << prompt << endl;
cin >> userChoice;
if (userChoice == "Y" || userChoice == "y" || userChoice == "N" || userChoice == "n") {
validFlag = true;
return userChoice;
}
else {
cout << "Sorry, that is not a valid option. Please enter Y for yes or N for no." << endl;
}
}
return "";
}