Code:
void tomarket(char *pick1,char *pick2,char *pick3,char *pick4, float *grams1,float *grams2,float *grams3,float *grams4)
/*goes to market..
(note that you can only go there once)*/
{
system("CLS");
char dump;
/*This will show up the fruits*/
char fruits[10][11]={"pears","figs","watermelons","tamarinds","avocados",
"okras","celeries","arugulas","endives","lemons"};
printf("\n\n\n"
" |======================GO TO MARKET=====================|\n"
" | Choose which food you want to buy from the market: |\n"
" |Press.. |\n"
" | [0] Pear |\n"
" | [1] Figs |\n"
" | [2] Watermelon |\n"
" | [3] Tamarind |\n");
printf(" | [4] Avocado |\n"
" | [5] Okra(RAW) |\n"
" | [6] Celery(RAW) |\n"
" | [7] Arugula(RAW) |\n"
" | [8] Endive(RAW) |\n"
" | [9] Lemon |\n"
" |=======================================================|\n"
"Pick your first food: ");
scanf("%c%c", &pick1,&dump);
printf("Enter how many grams you will get for the first: ");
scanf("%f%c", &grams1,&dump);
printf("Pick your second food: ");
scanf("%c%c", &pick2,&dump);
printf("Enter how many grams you will get for the second: ");
scanf("%f%c", &grams2,&dump);
printf("Pick your third food ");
scanf("%c%c", &pick3,&dump);
printf("Enter how many grams you will get for the third: ");
scanf("%f%c", &grams3,&dump);
printf("Pick your fourth food ");
scanf("%c%c", &pick4,&dump);
printf("Enter how many grams you will get for the fourth: ");
scanf("%f%c", &grams4,&dump);
printf(" You bought:\n");
printf(" %.1f g of %s\n", grams1,fruits[pick1]);
printf(" %.1f g of %s\n", grams2,fruits[pick2]);
printf(" %.1f g of %s\n", grams3,fruits[pick3]);
printf(" %.1f g of %s\n", grams4,fruits[pick4]);
system("PAUSE");
system("CLS");
main();
}
void totalnutribought(char pick1,char pick2,char pick3,char pick4,
float grams1,float grams2,float grams3,float grams4,
float pear[], float fig[], float water[], float tama[],
float avo[],float okra[],float cele[],float aru[],
float endive[],float lemon[])
/*Compute Total Nutrients to be gained from bought foods*/
{float pearinfo [7]={12,0.3,0.18,16,41,7.5,0.21};
float figinfo [7]={6,0.37,0.15,35,142,2.0,0.11};
float waterinfo[7]={5,0.36,0.15,11,865,12.3,0.08};
float tamainfo [7]={3,0.56,0.02,15,6,0.7,0.02};
float avoinfo [7]={30,0.21,0.24,4,55,3.8,0.78};
float okrainfo [7]={44,0.4,0.3,40,188,10.6,0.18};
float celerinfo[7]={29,0.16,0.1,32,359,2.5,0.22};
float aruinfo [7]={19,0.29,0.09,32,475,3.0,0.09};
float endinfo [7]={71,0.41,0.4,26,1084,3.2,0.22};
float leminfo [7]={9,0.5,0.05,22,18,44.5,0.13};
char fruits[10][11]={"pears","figs","watermelons","tamarinds","avocados",
"okras","celeries","arugulas","endives","lemons"};
printf("Food | %.1f g %s %.1f g %s %.1f g %s %.1f g %s\n",
grams1,fruits[pick1],grams2,fruits[pick2],grams3,fruits[pick3],
grams4,fruits[pick4]);
printf("Folic Acid | %.1f mcg %.1f mcg %.1f mcg %.1f mcg\n");
printf("Iron | %.1f mg %.1f mg %.1f mg %.1f mg\n");
printf("Zinc | %.1f mg %.1f mg %.1f mg %.1f mg\n");
printf("Calcium | %.1f mg %.1f mg %.1f mg %.1f mg\n");
printf("Vitamin A | %.1f I.U. %.1f I.U. %.1f I.U. %.1f I.U.\n");
printf("Vitamin C | %.1f mg %.1f mg %.1f mg %.1f mg\n");
printf("Vitamin E | %.1f mg %.1f mg %.1f mg %.1f mg\n");
system("PAUSE");
main();
}
int main()
{system("color 2f");
int ans;
char pick1;
char pick2;
char pick3;
char pick4;
float grams1;
float grams2;
float grams3;
float grams4;
do
{
/*This will show how the user should input ... it is almost like menu*/
printf("\n\n"
" ,-.-. | \n"
" | | |,--- |__/ ,--. ,-.-.,---. \n"
" | | |,---|| \ |---' | | ||---' \n"
" ` ' '`---^` ``---' ` ' '`---' \n"
" | | | | | \n"
" |---|,---.,---.| |--- |---., .\n"
" | ||---',---|| | | || |\n");
printf(" | |`---'`---^`---'`---'` '`---|\n"
" `---'\n"
"\n\n\n"
"+++++++++++++++++++++++++++MAIN MENU++++++++++++++++++++++++++++++\n"
" Press [1] Preview Market Selections\n"
" [2] Compute number of servings from amount of food\n"
" [3] Compute Nutrient Information of given good\n"
" and corresponding amount\n");
printf(" [4] Go to Market\n"
" [5] Compute Total Nutrients to be gained from\n"
" bought foods\n"
" [6] Feedback\n"
" [7] New Day\n"
" [8] Exit\n");
scanf("%d",&ans);/*makes users pick*/
switch(ans)
{
case 1: preview();break;
case 2: servings();break;
case 3: comnutrinfo();break;
case 4: tomarket(&pick1,&pick2,&pick3,&pick4,&grams1,
&grams2,&grams3,&grams4);break;
case 5: totalnutribought(pick1,pick2,pick3,pick4,grams1,
grams2,grams3,grams4);break;
case 6: servings();break;
case 7: servings();break;
case 8: {system("ClS");
printf("\n\n\n"
" ######## ## ## ######## ####\n"
" ## ## ## ## ## ####\n"
" ## ## #### ## ####\n"
" ######## ## ###### ## \n"
" ## ## ## ## \n"
" ## ## ## ## ####\n"
" ######## ## ######## ####\n");
system("EXIT");break;
}
default:{printf("Please enter the right option..\n");
system("PAUSE");
main();break;
}
}
}
while(ans!=8);
system("PAUSE");
return 0;
}