By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,530 Members | 891 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,530 IT Pros & Developers. It's quick & easy.

I am writing a program passing functions to arrays

P: n/a
i am passing a float and a integer into the function

error: function does not take 1 arguments

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #define AgentSize 5
  6. void DisplayWelcome(void);
  7. void Type(int);
  8. void category();
  9. void Budget(float);
  10.  
  11. int main()
  12. {
  13. char Agentfinitial[AgentSize], Agentlinitial[AgentSize];
  14. int i=0, AType[AgentSize], MaxAgent[AgentSize]={0};
  15. int AgentType[AgentSize]={0};
  16. float ibudget[AgentSize], excess[AgentSize]={0}, totmissionbudget[AgentSize]={0};
  17. int Agent[AgentSize]={0}, Agentctr[AgentSize]={0}; 
  18. char cat;
  19.  
  20.  
  21.  
  22. DisplayWelcome();
  23. for (i=0; i<AgentSize; i++)
  24. {
  25. printf("\nPlease enter first and last initial\n");
  26. scanf("%c%c", &Agentfinitial[AgentSize], &Agentlinitial[AgentSize]);getchar();
  27.  
  28. printf("\nPlease enter Agent Type\n");
  29. scanf("%d", &AType[AgentSize]);getchar();
  30. Type(AType[AgentSize]);
  31.  
  32. printf("\nYou are allowed an additional 5%% of your budget\n");
  33. printf("\nPlease enter budget\n");
  34. scanf("%f", &ibudget[AgentSize]); getchar();
  35. Budget(ibudget); <<AT THIS POINT


THIS IS THE FUNCTION:
Expand|Select|Wrap|Line Numbers
  1. void Budget(float ibudget[AgentSize],int AType[])
  2.  
  3. {
  4. float excess[AgentSize]={0}, totmissionbudget[AgentSize]={0};
  5.  
  6. if (AType[AgentSize]==1)
  7. {
  8.  
  9. excess[AgentSize] =  ibudget[AgentSize]* 0.05;
  10. totmissionbudget[AgentSize]= excess[AgentSize] + ibudget[AgentSize];
  11. printf("\nThe total mission budget is %f", totmissionbudget[AgentSize]);
  12.             }
  13. else  if(AType[AgentSize]==2)
  14. {
  15. printf("\n This agent is not allowed an excess\n");
  16. totmissionbudget[AgentSize] = ibudget[AgentSize] + totmissionbudget[AgentSize];
  17. printf("\nThe total mission budget is %f", totmissionbudget[AgentSize]);
  18. }
  19.  
  20.  else if (AType[AgentSize]==3)
  21. {
  22. printf("\nThis Agent will incur a 5%% penalty if overbudget\n");
  23. totmissionbudget[AgentSize] = ibudget[AgentSize]+totmissionbudget[AgentSize];
  24. printf("\nThe total mission budget %f", totmissionbudget[AgentSize]);
  25. }
  26.  
  27.  else 
  28. {
  29. Printf("\nYou need to enter a budget\n");
  30. }
  31.  
  32.  
  33.         }//end budget function
Nov 25 '10 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,398
Expand|Select|Wrap|Line Numbers
  1. void Budget(float);
  2. ...
  3. float ibudget[AgentSize];
  4. ...
  5. Budget(ibudget);
  6. ...
  7. void Budget(float ibudget[AgentSize],int AType[]) {
  8.    ...
  9.    }
Your prototype says Budget has a single float argument; you pass an array of floats when you call Budget; and you define Budget with two arguments: an array of float and an array of int. The compiler doesn't like inconsistencies like these.

By the way, the compiler doesn't enforce any particular size for array arguments so specifying the size of the ibudget array in the declaration doesn't accomplish anything. Refer to Arrays Revealed for advice on how to pass arrays to functions.
Nov 26 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.