Yahoo Answers is shutting down on 4 May 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Help me With C code 2 Dimensional arrays?

void printAveageCost(Mealtype *MEALS, Locationtype *LOCATION,float *PRICE)

{

int x;

float breakfast=0.0;

float MealsTotal=0.0;

float breakfastAvg;

int breakfastCount;

float lunch;

float MealsAverage;

float lunchAvg;

int lunchcount;

int mealCount;

float dinner;

float dinnerAvg;

int dinnerCount;

for(x=0;x<8;x++)

{

if (Mealtype[x]="Breakfast")// HELP HERE

{

breakfast=breakfast+PRICE[x];

MealsTotal=MealsTotal+PRICE[x];

breakfastCount=breakfastCount+1;

mealCount=mealCount+1;

}

if (MEALS[x]="Lunch")// HELP HERE

{

lunch=lunch+PRICE[x];

MealsTotal=MealsTotal+PRICE[x];

lunchcount=lunchcount+1;

mealCount=mealCount+1;

}

if (MEALS[x]="Dinner")// HELP HERE

{

dinner=dinner+PRICE[x];

MealsTotal=MealsTotal+PRICE[x];

dinnerCount=dinnerCount+1;

mealCount=mealCount+1;

}

breakfastAvg = breakfast / breakfastCount;

lunchAvg = lunch / lunchcount;

dinnerAvg = dinner / dinnerCount;

MealsAverage= MealsTotal / mealCount;

printf("Average cost of Breakfast %f",breakfastAvg);

printf("Average cost of Lunch %f",lunchAvg);

printf("Average cost of Dinner %f",dinnerAvg);

printf("Average cost of All Meals %f",MealsAverage);

}

}

I can figure out what to do to those 3 lines to make it behave acceptably.

2 Answers

Relevance
  • Anonymous
    1 decade ago
    Favourite answer

    It should be Mealtype[x]=="Breakfast".

    Note the double equal to(==).

    Cheers!

    Any probs in programming contact me: naveen_4688@yahoo.com

  • CSpace
    Lv 5
    1 decade ago

    Naveen nailed it, also use it for Lunch and Dinner.

    When using if, switch or any other comparison use ==

    where = is assigning it.

Still have questions? Get answers by asking now.