c - How do I point to an array through an if loop -


ok, trying write program bid on cars. i'm trying if current bid zero, minimum bid starting bid. if current bid not zero, minimum bid current bid plus minimum bid. keep getting error says incompatible types when assigning type 'float[5]' type 'float'.

here code:

    #include <stdio.h>     #include <stdlib.h>     #include <string.h>      int menu1();      int main()     {         file * ifp = fopen("input2.txt","r"); //open input file         int cars = 5, , j, k; // initialized cars , counters i, j, , k         char *view="view", *bid="bid", *close="close", choice1[20]; //initialize character arrays         float car[5]={1,2,3,4,5},start_bid[5]={0.00}, min_bid[5]={0.00}, cur_bid[5]={0.00}, usr_bid[5]={0.00}; //initialized float arrays         int comparelimit = 100, selection=0;          //scan file , appropriate numbers respective arrays         (i = 0; < cars; i++)             {                 fscanf(ifp, "%f %f", &start_bid[i],&min_bid[i]);             }           printf("welcome silent auction\n\n");         menu1(); //display menu           while (selection < 3)     {             scanf("%s", choice1);              int result = strncmp(choice1, view, comparelimit); //compare 2 strings             if(result == 0)             {                 selection = 1;              }               int result2 = strncmp(choice1, bid, comparelimit); //compare 2 strings             if(result2 == 0)             {                 selection = 2;              }              int result3 = strncmp(choice1, close, comparelimit); //compare 2 strings             if(result3 == 0)             {                 selection = 3;             }              if (selection == 1)             {                 printf("number\tcurrent bid\tminimum increase\n");                 printf("1\t$%.2f\t\t$%.2f\n",cur_bid[0], min_bid[0]);                 printf("2\t$%.2f\t\t$%.2f\n",cur_bid[1], min_bid[1]);                 printf("3\t$%.2f\t\t$%.2f\n",cur_bid[2], min_bid[2]);                 printf("4\t$%.2f\t\t$%.2f\n",cur_bid[3], min_bid[3]);                 printf("5\t$%.2f\t\t$%.2f\n",cur_bid[4], min_bid[4]);                  menu1();             }               else if (selection == 2)             {                 int k;                 float usr_bid;                  printf("which auction bid on? (1-5)\n");                 scanf("%d", &k);                  if (cur_bid[k-1] != 0.00)                     min_bid = cur_bid[k-1] + min_bid[k-1];                 else                     printf("the minimum bid %.2f\n", min_bid[k - 1]);                  printf("how bid?\n");                 scanf("%f", &usr_bid);                 if (usr_bid < min_bid[k-1])                     printf("sorry, bid not high enough.\n");                 else                     cur_bid[k-1] = usr_bid + cur_bid[k-1];                  menu1();             }              else             {                 int i;                  (i=0; i<cars; i++)                     if (cur_bid!=0)                         printf("auction %d sold $%f\n", car[i],cur_bid[i]);                     else                         printf("auction %d did not sell.\n");                  break;             }     }              fclose(ifp);          return 0;     }       int menu1()     {     printf("please make selection (in caps):\n");         printf("\tview auctions [view]\n");         printf("\tbid on auction [bid]\n");         printf("\tclose auctions [close]\n");     } 

what code doing in else if (selection == 2) section asks bid want bid on. whatever number choose 1-5 in int k. checks current bid selection looks in cur_bid[k-1] array if number 3, checks in 2nd spot in array. getting error from:

    min_bid = cur_bid[k-1] + min_bid[k-1];  

any ideas?

min_bid array of floats, yet you're trying assign single float it. looks want min_bid[k-1] = cur_bid[k-1] + min_bid[k-1];.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -