Assume that two parallel arrays have been declared and initialized: healthOption an array of type char that contains letter codes for different healthcare options and annualCost an array of type int. The i-th element of annualCost indicates the annual cost of the i-th element of healthOption. In addition, there is an char variable, best2.Write the code necessary to assign to best2 the health option with the lower annual cost, considering only the first two healthcare options.

Respuesta :

/*

Since we have to check the first two options only as mentioned in last part of question the loop will work 2 times only and will compare the cost of first element and second and assign the healthoption accordingly

*/

for(int i =0;i<=1;i++){

if(annualCost[i]<annualCost[i+1]

best2 = healthOption[i]

else

best2 = healthOption[i+1]

}