#include #include #include "prompt.h" long int PromptRange(apstring prompt,long int low, long int high) // precondition: low <= high // postcondition: returns a value between low and high (inclusive) { long int value; apstring response; do { cout << prompt << " between "; cout << low << " and " << high << ": "; cin >> response; value = atol(response.c_str()); } while (value < low || high < value); return value; } static void eatline() { apstring dummy; getline(cin,dummy); } long int PromptlnRange(apstring prompt,long int low, long int high) // precondition: low <= high // postcondition: returns a value between low and high (inclusive) { long int retval = PromptRange(prompt,low,high); eatline(); return retval; } int PromptRange(apstring prompt,int low, int high) // precondition: low <= high // postcondition: returns a value between low and high (inclusive) { int value; apstring response; do { cout << prompt << " between "; cout << low << " and " << high << ": "; cin >> response; value = atoi(response.c_str()); } while (value < low || high < value); return value; } int PromptlnRange(apstring prompt,int low, int high) // precondition: low <= high // postcondition: returns a value between low and high (inclusive) { int retval = PromptRange(prompt,low,high); eatline(); return retval; } double PromptRange(apstring prompt,double low, double high) // precondition: low <= high // postcondition: returns a value between low and high (inclusive) { double value; apstring response; do { cout << prompt << " between "; cout << low << " and " << high << ": "; cin >> response; value = atof(response.c_str()); } while (value < low || high < value); return value; } double PromptlnRange(apstring prompt,double low, double high) // precondition: low <= high // postcondition: returns a value between low and high (inclusive) { double retval = PromptRange(prompt,low,high); eatline(); return retval; } apstring PromptString(apstring prompt) // postcondition: returns string entered by user { apstring str; cout << prompt; cin >> str; return str; } apstring PromptlnString(apstring prompt) // postcondition: returns string entered by user { apstring str; cout << prompt; getline(cin,str); return str; } bool PromptYesNo(apstring prompt) // postcondition: returns true iff user enters yes { apstring str; char ch; do { cout << prompt << " "; cin >> str; ch = tolower(str[0]); } while (ch != 'y' && ch != 'n'); return ch == 'y'; } bool PromptlnYesNo(apstring prompt) // postcondition: returns true iff user enters yes { bool retval = PromptYesNo(prompt); eatline(); return retval; }