
Patrick B. answered 05/08/21
Math and computer tutor/teacher
#include <stdio.h>
// There are TWO issues.....
calculateStimulus( int * Ages)
{
// sizeof(Ages)/sizeof(Ages[0] will not work because the BASE ADDRESS (a pointer) MUST be passed
// this is not a problem in Java, as the array has property Array.length;
int iLoop=0;
int age;
int amount=0;
int N = Ages[0];
for (iLoop=1; iLoop<=N; iLoop++)
{
age = Ages[iLoop];
/* The cut-off points of these ages are UNCLEAR!!
the word "UP to" does not help....
YOU may have to move the equal sign from one case to the next ... */
if (age<18)
{
amount = 0;
}
else if (age>=18 && age <=21) //does someone age 21 get 500 or 1000 ?
{
amount = 500;
}
else if (age>21 && age<55) //does someone age 55 get 1000 or 1500 ?
{
amount = 1000;
}
else if (age>=55 && age<=65)
{
amount = 1500;
}
else //CRYSTAL CLEAR: anyone over 65 gets 2000
{
amount=2000;
}
printf("Person at Index %d : Age %d : Amount $ %d \n",iLoop,age,amount);
}
}
main()
{
//first element in the array is the # of ages that follow
int ages[]={20,5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100};
int Ages[] = {13,8,16,24,32,40,48,56,64,72,80,88,96,104};
calculateStimulus(ages);
printf("-------------------------------\n");
calculateStimulus(Ages);
}