Hopefully someone knows C and can help me here. I have code for a cruise reservation. However, I am having a hard time finding why my total prints an insanely large number, and why when I print the meal plan for the family if they select the second option it prints almost twice as many times as I want.
#include <stdio.h>
int familyOne(int *famoneMeal[9], int mealSelection);
int main() {
int famOne[3];
int *famoneMeal[9];
int famTwo[4];
int *famtwoMeal[4];
int mealSelection;
int familyoneTotal;
printf("Thank you for selecting ECPI as your cruise provider!\n");
printf("Lets start by entering the age for each member in your reservation group ");
scanf("%d", &famOne[0], &famOne[1], &famOne[2] );
printf("\nLooks like we have two families taking this cruise!\n");
printf("Second family please enter the age for each member in your reservation group ");
scanf("%d", &famTwo[0], &famTwo[1], &famTwo[2], &famTwo[3]);
printf("\n");
printf("Excellent! Family one please select your meal plan for the trip\n ");
printf("Plan one (1) offers this deal: Breakfast $5, Lunch $10, and Dinner $15\n");
printf("Plan Two (2) offfers this deal: Breakfast $10 (enough food for 3), and dinner $20 (Enough food for 3)" );
scanf("%d", &mealSelection);
familyOne(&famoneMeal, mealSelection);
familyoneTotal = familyOne(&famoneMeal, mealSelection);
printf("The total for Family One selected meal plan is %d", familyoneTotal);
}
int familyOne(int *famoneMeal[9], int mealSelection ){
int total;
if(mealSelection == 1){
famoneMeal[0] = 5;
famoneMeal[1] = 10;
famoneMeal[2] = 15;
famoneMeal[3] = 5;
famoneMeal[4] = 10;
famoneMeal[5] = 15;
famoneMeal[6] = 5;
famoneMeal[7] = 10;
famoneMeal[8] =15;
int i;
for( i=0; i<=8; i++){
total = total + famoneMeal[i];
printf("Cost of your meal plans %d \n", famoneMeal[i]);
}
}
else if(mealSelection == 2){
famoneMeal[0] = 10;
famoneMeal[1] = 20;
famoneMeal[2] = 10;
famoneMeal[3] = 20;
famoneMeal[4] = 10;
famoneMeal[5] = 20;
int i;
for( i=0; i<=4; i++){
total += famoneMeal[i];
printf("Cost of your meal plans %d \n", famoneMeal[i]);
}
}
return total;
}