Hi,
How would I use an array that doesn't have a size in its declaration? I want this array to be assigned an unknown number of values over the course of the program , but trying to declare an array of 0 size can't be done.
Code:
double valid_rates[VALID_PAY_RATES] = {3.50, 4.00, 4.50, 4.75, 5.00, 5.50, 5.75, 6.00},
invalid_rates[UNKNOWN_VALUE],
rate;
int hours;
printf("\nPlease enter the number of hours: ");
scanf("%d" , &hours);
printf("\nPlease enter the rate of pay: ");
scanf("%lf" , &rate);
for(individual_rates=0; individual_rates<VALID_PAY_RATES; ++individual_rates)
if(rate == valid_rates[individual_rates])
{
if(hours > 40)
{
hours_overtime = hours - 40;
overtime_pay = hours_overtime * (1.5 * rate);
regular_pay = rate * 40;
}
else
regular_pay = rate * hours;
printf("\nThe regular pay is %2.2f", regular_pay);
printf("\nThe overtime pay is %2.2f", overtime_pay);
printf("\nThe gross pay is %2.2f\n\n", overtime_pay + regular_pay);
grand_total_salaries += overtime_pay + regular_pay;
++num_of_employees;
overtime_pay=0;
printf("\nDo you want to process another employee?(1 for yes, 0 for no): ");
scanf("%d" , &response);
break;
}
else
if((rate != valid_rates[individual_rates]) && (individual_rates == VALID_PAY_RATES-1))
{
printf("\nERROR:INVALID PAY RATE, valid rates are: ");
printf("\n$3.50 $4.00 $4.50 $4.75 $5.00 $5.50 $5.75 $6.00 -- Please try again\n\n");
invalid_rates[UNKNOWN_VALUE] = rate;
/*each time there is an invalid rate entered, it
should be stored in invalid_rates[](somehow)*/
}
any help would be appreciated.