Question: This is my header file. I need help making a function that rejects bad inputs using the header file. 10-17-18 getInt asks for an integer
This is my header file. I need help making a function that rejects bad inputs using the header file.
10-17-18
getInt asks for an integer and rejects bad inputs outside the range.
getDouble asks for a decimal number and rejects bad inputs outside the range.
getYN asks for Y or N and reject bad inputs other than Y or N.
*****************************************************************************/
#include
using namespace std;
/******************************************************************************
min is the minimum value accepted
max is the maxmum value accepted
msg is the message shown when the user's input was outside the range.
This function will read in an integer number and keeps asking to enter a number
as long as a number outside the range is entered. It will return a number within
the range (between min and max inclusive).
*******************************************************************************/
int getInt(int min, int max, string msg)
{
int n; //user's input
cin >> n;
while(n < min || n > max) // the user's input was outside the range
{
cout << msg; //show the message to the user
cin >> n; //read a new input
}
return n; //return a good value that is within the range (between min and max enclusive)
}
/******************************************************************************
Explain each paramter
Explain what the function does
*******************************************************************************/
double getDouble(double min, double max, string msg)
{
double n;
cin>>n;
while(n < min || n> max)
{
cout< cin>>n; } return n; } /****************************************************************************** msg is the message shown when the user inputs a character other than Y or N. Explain what the function does. ******************************************************************************/ char getYN(string msg) { char c; cin >> c; while(c !='Y' && c!= 'N'){ cout << msg; cin >> c; } return c; } Here is how the function should work Write a function called getCustomerInfo that reads from the keyboard the account number, the date of sale (month, day, and year as 3 integers), the county code (S for San Diego County, O for Orange County and L for LA county). Reject bad inputs Sample run for the getCustomerInfo function Valid inputs Account number: 1000 9999 Month: 1-12 Day: 1-31 Year: 2000-2100 County Code: Uppercase S, O or L only Write a while loop inside this function to reject bad county codes Use getInt() in input.h Use getInt() in input.h Use getInt() in input.h Use getInt() in input.h Enter an account number: 10000 getInt() in input.h rejects bad inputs An account number must be be 1000 9999. Enter again: 999 An account number must be be 1000 9999. Enter again: 1234 Enter a month: 0 getInt() in input.h rejects bad inputs A month must be 1 12. Enter again: 13 A month must be 1 12. Enter again: 12 Enter a day: 0 getInt() in input.h rejects bad inputs A day must be 1 31. Enter again: 32 A day must be 1 31. Enter again: 1 Enter a year: 1999 getInt() in input.h rejects bad inputs A year must be 2000 2100. Enter again: 2101 A year must be 2000 2100. Enter again: 2018 Enter a county code. Enter S, O or L: A Write a while loop to reject bad inputs inside this functionInvalid county code. Enter uppercase S, O or L: s Invalid county code. Enter uppercase S, O or L: S Write a function called getItemsInfo that reads the prices and the weights (integer) of the items the customer is ordering. You dont know how many items the customer is buying. In this function, you need to sum up the prices (total sale amount) and the weights (total weight). The total sale amount and total weight will be used to calculate a discount, the sales tax, and the shipping cost. Reject bad inputs Valid inputs Users Y or N answer: uppercase Y or N only Price: 0.00 999.99 Weight: 0 - 99 Use getYN() iin input.h Use getDouble() in input.h Use getInt() in input.h Sample run for the getItemsInfo function Do you want to order an item? Enter Y or N: X getYN() in input.h rejects bad inputsInvalid response. Enter uppercase Y or N: A Invalid response. Enter uppercase Y or N: Y Enter a price: -0.99 getDouble() in input.h rejects bad inputs A price must be between 0.00 and 999.99. Enter again: 1000.01 A price must be between 0.00 and 999.99. Enter again: 5.55 Enter a weight: 100 getInt() in input.h rejects bad inputs A weight must be between 0 and 99. Enter again: -1 A weight must be between 0 and 99. Enter again: 3 Do you want to order another item? Enter Y or N: y Invalid response. Enter uppercase Y or N: Y Enter a price: 10.20 Enter a weight: 5 Do you want to order another item? Enter Y or N: n Invalid response. Enter uppercase Y or N: N lowercase y is rejected by getYN() lowercase n is rejected by getYN() Hints cout << " Do you want to order an item? Enter Y or N: "; call getYN() in input.h while(??????????) { : : cout << " Do you want to order another item? Enter Y or N: "; ??????????? }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
