I’m having an issue with trying to figure out how to use the same function (validate), to validate 2 different number inputs, using 2 different questions
int validate(int low, int high) {
int flag = 0, number = 0;
do
{
printf("Enter maximum value between %d and %d: ", low, high);
scanf("%d", &number);
if (number <= low || number > high)
{
printf("INVALID! Must enter a value between %d and %d: ", low, high);
scanf("%d", &number);
}
else {
flag = 1;
}
} while(flag == 0);
return number;
}
Here is main()
int main () {
int num1, num2;
switch(menu()) {
case 1:
printf("~~~~~~~\n6/49 Number Generator\n");
num1 = validate(1,49);
num2 = validate(1, 6);
break;
default:
printf("end");
}
return(0);
}
When I call validate() the second time (returning num2), I need it to ask for a quantity of numbers.
Any help would be appreciated.
Ideally your validate() should have another parameter signifying what it’s gonna actually do.
Something like
int validate(int low, int high, int type).Then switch on type to do the various operations. But then I’d advise you to change the name of the function as validate would not be too appropriate. e.g.
numGenEnginewhere type would signify step1, step2 etc.Considering you need the function definition intact, you can use static variable.