How to pass or declare array members in c? -


i developed program supposed pass following members of array of double purchase following function:

float beverages () {                  char response;    double purchase [8]= {3.50, 3.80, 3.90, 4.20, 4.00, 4.30, 3.00, 3.10};    printf("\nenter order: ");    scanf("%c", response);     if (response == 'l')    {       purchase [0];       printf("you have chosen regular long black coffee\n");       printf("that %.2f dollars", purchase [0]);      }    else if (response == 'l')    {       purchase [1];       printf("you have chosen large long black coffee\n");       printf("that %.2f dollars", purchase [1]);     }    else if (response == 'f')    {       purchase [2];       printf("you have chosen regular flat white coffee\n");       printf("that %.2f dollars", purchase [2]);      }    else if (response == 'f')    {       purchase [3];       printf ("you have chosen large flat white coffee\n");       printf("that %.2f dollars", purchase [3]);      }     else if (response == 'c')    {       purchase [4];       printf("you have chosen regular cappuccino\n");       printf("that %.2f dollars", purchase [4]);        }    else if (response == 'c')    {       purchase [5];       printf("you have chosen large cappuccino\n");       printf("that %.2f dollars", purchase [5]);            }    else if (response == 't')    {       purchase [6];       printf("you have chosen regular tea\n");       printf("that %.2f dollars", purchase [6]);        }    else  if (response == 't')    {       purchase [7];       printf("you have chosen large tea\n");       printf("that %.2f dollars", purchase [7]);        }     return purchase[]; }    

and have in int main like:

int main() {   ...   printf("menu!");   decision (choice);   purchase [] = beverages();   ...   return 0; }   

with following code purchase [] = beverages(); there seems problem compiler saying purchase undeclared , there , unexpected expression before ] token (by way errors within int main). seems maybe have not passed array function or something? i've tried adding value 8 e.g purchase[8] = beverages(); compiler says purchase not pointer or array. how debug this? not using right syntax or not passing array correctly?

as 'beverages()' function want return double array need modify

  double * beverages()      {                 static double purchase [8]= {3.50, 3.80, 3.90, 4.20, 4.00, 4.30, 3.00, 3.10};         // line of code         return purchase;      } 

in main function need modify like

main() {    double *purchase = beverages();      } 

variable purchase defined in beverages() local function can not access in main()


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -