Number Validation with two Data

Hello I'm a beginner C++ coder and currently taking Programming Structure class. The professor asked us to create a function that can validate the input numbers is correct form of number and limit the input numbers for pay rates to 99.99 and hours worked to 112.00. So far I am able to validate the pay rate to be 99.99 but instead of creating a whole new function to validate hours worked. I want to have the pay rate validation to also validate the hours worked as well. I want to know what I am missing to implement this code?
Thanks ahead of time.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
         getValidatedNumber("Enter hourly pay rate: ",payrate);
         getValidatedNumber("Enter hours worked this pay period: ",hours);
...

void getValidatedNumber (char *prompt,float *validatedNumber)
{
	int reTryCount=0;
	BOOLEAN ValidNumber;
	do {
		printf(prompt);
		scanf("%f",validatedNumber);
                  ValidNumber = ValidateNumber(*validatedNumber,0,99.99);
		if (!ValidNumber) reTryCount++;
    } while (reTryCount < RETRYMAX && !ValidNumber);
    if (reTryCount > RETRYMAX && !ValidNumber);
If you're going to use a single function to validate both numbers, then, you're going to need to pass in the max value as an argument.

1
2
  getValidatedNumber("Enter hourly pay rate: ",payrate, 99.00);
  getValidatedNumber("Enter hours worked this pay period: ",hours, 112.00);


And of course line 12 will need to change to check the passed value.

I just thought it through. Thanks for the help.
Last edited on
Topic archived. No new replies allowed.