Another problem has occoured. How can I get the highlighted function to run? Whenever I run the program, the function is totally skipped.

void add()
{
     int vala, valb, valc, bog=5, count;
	 char alakazam;
     double log[0], vald, valf;
     clearer();
     do
       {
       for(count = 0; count < 5; count++)
                 {
                 vala = getint("Product Number", mnum, maxnum);
                 valb = getint("Product Type", mtype, maxtype);
                 valc = getint("Quantity", minquan, maxquan);
                 vald = getreal("Cost", mincost, maxcost);
                 show_costs(log, vald);
                 valf = getreal("Price", minprice, maxprice);
                 show(vala, valc, vald, valf);
                  }
       printf("Again? (Y/N)");
       scanf("%c%*c", &alakazam);
       }
  
  while(alakazam == 'Y' || alakazam == 'y');
  return;
/*==============================================*/
double show_costs(double n[], double c)
{
       int scrub=0, bammo;
       if(scrub < 5)
       {
           n[scrub] == c;
           scrub++;
       }
       else
       {
           printf("Type-------------------------Cost");
           for(bammo=0; bammo < 5; bammo++);
           printf("%d:---------------------------%lf", bammo, n[bammo]);
           getchar();
       }
       return 0;
}
       
       
/*====================================================================*/

it's not being skipped. it's running, and doing exactly what you've told it to do. which, unfortunately, is not what you intended it to do.

every time the "count" loop in main() is executed, it calls your subroutine. every time the subroutine is called, it sets "scrub = 0". scrub is always less than 5, so the first condition is always executed. the second condition will never occur.

you need to make "scrub" a variable declared in "main()" and have it passed as a pointer to the subroutine. assuming that you want scrub to be incremented, as it appears.

there are other ways to do it, of course, such as declaring 'scrub' global in scope (outside main). But i don't recommend that option ... although others may recommend it just as a "get-r-dun" sort of thing.

Ok, I have fixed my problem. Thank you for the help, but a new one has arisen. I am new to arrays, and can't get values taken from add(); to apply to the array.

Where is my bug?

Sorry to be such a noob, but in reality, I just started two months ago.

main();

int main(void)           /*Start*/
{ 
     int key;
     do
     {
     key = menu();
     switch (key)
            {
                 case 1: add(); break;
                 case 2:
                 case 3:
                 case 4:
                 case 5: break;
                 default: printf("Error in selection");
            }
     }
     while(key != 5);
     return 0;
}

add();

void add()
{
     int vala, valb, valc, count=0;
	 char alakazam;
     double log[5], vald, valf;
     clearer();
     do
       {
       for(count = 0; count < 5; count++)
                 {
                 vala = getint("Product Number", mnum, maxnum);
                 valb = getint("Product Type", mtype, maxtype);
                 valc = getint("Quantity", minquan, maxquan);
                 vald = getreal("Cost", mincost, maxcost);
                 show_costs(log, vald, count);
                 valf = getreal("Price", minprice, maxprice);
                 show(vala, valc, vald, valf);
                  }
       printf("Again? (Y/N)");
       scanf("%c%*c", &alakazam);
       }
  
  while(alakazam == 'Y' || alakazam == 'y');
  return;
}

show_costs();

double show_costs(double n[], double c, int count)
{

       int bammo;
       if(count < 4)
       {
           n[count] == c;
           printf("A file has been entered.\n\n");
       }
       else
       {
           printf("Type-------------------------Cost");
           printf("%d:---------------------------%lf\n", 1, n[0]);
           printf("%d:---------------------------%lf\n", 2, n[1]);
           printf("%d:---------------------------%lf\n", 3, n[2]);
           printf("%d:---------------------------%lf\n", 4, n[3]);
           printf("%d:---------------------------%lf\n", 5, n[4]);
       }
       return 0;
}

The following is not an assignment

n[count] [B]==[/B] c;

instead use

n[count] = c;

Didn't your compiler complain about that line?

what he said ^, and also, your function

show_costs

should have the conditional "count<5". otherwise the index [4] never gets set

Thank you very much! All problems fixed, and my program works bug-less. Bravo!

This article has been dead for over six months. Start a new discussion instead.