C code Error not a function or function pointer












1














I have the following C code. When i try to compile it, i get an error message:



called object 'countPassed' is not a function or function pointer"


How may I fix this?



#include <stdio.h>

int main()
{
int countWhoPassed, averageCalculate, printPassed;
int amount = howManygrades();
storesGrades(amount);
printAll(amount);
averageCalculate = averageCalc(amount);
printAverage(amount);
countWhoPassed = countPassed(amount);
printPassed = printWhoPassed(amount);
return 0;
}

int howManygrades()
{
int gradesAmount;
printf("How many grades do you want?n");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
}
}
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
}
}

return gradesAmount;
}

void storesGrades(int amount)
{
int iterator;
float grade;
for (iterator = 0; iterator < amount; iterator++)
{

printf ("Enter another grade.");
scanf("%f", &grade);
while ((grade <= 0.0) || (grade > 10.0))
{
printf("Sorry, this number is not valid.");
scanf("%f", &grade);
}
grades[iterator] = grade;
}
}

void printAll(int amount)
{
int iterator;
for (iterator = 0; iterator < amount; iterator++)
{
printf("%.1fn", grades[iterator]);
}
}

int averageCalc(int amount)
{
float sum, averageResult, average;
int iterator;
sum = 0.0;
for (iterator = 0; iterator < amount; iterator++) {
sum += grades[iterator];
}
average = sum / (float)amount;
return average;
}

void printAverage(int amount)
{
float printThisAverage = averageCalc(amount);
printf("%.2f", printThisAverage);
}

int countPassed(int amount)
{
int iterator, countPassing;
countPassing = 0;
for (iterator = 0; iterator < amount; iterator++)
{
if (grades[iterator] >= 5.5)
{
countPassing++;
}
}
return countPassing;
}

int printWhoPassed(int amount)
{
int returnValue = countPassed(amount);
return returnValue;
}









share|improve this question
























  • The message you get is a compilation error. You cannot run your code as it does not even compile. That set of code snippets is not a complete example or don't you use headers? See MCVE for details.
    – Gerhardh
    Nov 21 '18 at 11:27








  • 1




    Just guessing as too many details are missing: You might try to compile main without providing a prototype for that function.
    – Gerhardh
    Nov 21 '18 at 11:28










  • You don't declare the array grades in your code too
    – Chris Turner
    Nov 21 '18 at 11:38
















1














I have the following C code. When i try to compile it, i get an error message:



called object 'countPassed' is not a function or function pointer"


How may I fix this?



#include <stdio.h>

int main()
{
int countWhoPassed, averageCalculate, printPassed;
int amount = howManygrades();
storesGrades(amount);
printAll(amount);
averageCalculate = averageCalc(amount);
printAverage(amount);
countWhoPassed = countPassed(amount);
printPassed = printWhoPassed(amount);
return 0;
}

int howManygrades()
{
int gradesAmount;
printf("How many grades do you want?n");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
}
}
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
}
}

return gradesAmount;
}

void storesGrades(int amount)
{
int iterator;
float grade;
for (iterator = 0; iterator < amount; iterator++)
{

printf ("Enter another grade.");
scanf("%f", &grade);
while ((grade <= 0.0) || (grade > 10.0))
{
printf("Sorry, this number is not valid.");
scanf("%f", &grade);
}
grades[iterator] = grade;
}
}

void printAll(int amount)
{
int iterator;
for (iterator = 0; iterator < amount; iterator++)
{
printf("%.1fn", grades[iterator]);
}
}

int averageCalc(int amount)
{
float sum, averageResult, average;
int iterator;
sum = 0.0;
for (iterator = 0; iterator < amount; iterator++) {
sum += grades[iterator];
}
average = sum / (float)amount;
return average;
}

void printAverage(int amount)
{
float printThisAverage = averageCalc(amount);
printf("%.2f", printThisAverage);
}

int countPassed(int amount)
{
int iterator, countPassing;
countPassing = 0;
for (iterator = 0; iterator < amount; iterator++)
{
if (grades[iterator] >= 5.5)
{
countPassing++;
}
}
return countPassing;
}

int printWhoPassed(int amount)
{
int returnValue = countPassed(amount);
return returnValue;
}









share|improve this question
























  • The message you get is a compilation error. You cannot run your code as it does not even compile. That set of code snippets is not a complete example or don't you use headers? See MCVE for details.
    – Gerhardh
    Nov 21 '18 at 11:27








  • 1




    Just guessing as too many details are missing: You might try to compile main without providing a prototype for that function.
    – Gerhardh
    Nov 21 '18 at 11:28










  • You don't declare the array grades in your code too
    – Chris Turner
    Nov 21 '18 at 11:38














1












1








1







I have the following C code. When i try to compile it, i get an error message:



called object 'countPassed' is not a function or function pointer"


How may I fix this?



#include <stdio.h>

int main()
{
int countWhoPassed, averageCalculate, printPassed;
int amount = howManygrades();
storesGrades(amount);
printAll(amount);
averageCalculate = averageCalc(amount);
printAverage(amount);
countWhoPassed = countPassed(amount);
printPassed = printWhoPassed(amount);
return 0;
}

int howManygrades()
{
int gradesAmount;
printf("How many grades do you want?n");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
}
}
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
}
}

return gradesAmount;
}

void storesGrades(int amount)
{
int iterator;
float grade;
for (iterator = 0; iterator < amount; iterator++)
{

printf ("Enter another grade.");
scanf("%f", &grade);
while ((grade <= 0.0) || (grade > 10.0))
{
printf("Sorry, this number is not valid.");
scanf("%f", &grade);
}
grades[iterator] = grade;
}
}

void printAll(int amount)
{
int iterator;
for (iterator = 0; iterator < amount; iterator++)
{
printf("%.1fn", grades[iterator]);
}
}

int averageCalc(int amount)
{
float sum, averageResult, average;
int iterator;
sum = 0.0;
for (iterator = 0; iterator < amount; iterator++) {
sum += grades[iterator];
}
average = sum / (float)amount;
return average;
}

void printAverage(int amount)
{
float printThisAverage = averageCalc(amount);
printf("%.2f", printThisAverage);
}

int countPassed(int amount)
{
int iterator, countPassing;
countPassing = 0;
for (iterator = 0; iterator < amount; iterator++)
{
if (grades[iterator] >= 5.5)
{
countPassing++;
}
}
return countPassing;
}

int printWhoPassed(int amount)
{
int returnValue = countPassed(amount);
return returnValue;
}









share|improve this question















I have the following C code. When i try to compile it, i get an error message:



called object 'countPassed' is not a function or function pointer"


How may I fix this?



#include <stdio.h>

int main()
{
int countWhoPassed, averageCalculate, printPassed;
int amount = howManygrades();
storesGrades(amount);
printAll(amount);
averageCalculate = averageCalc(amount);
printAverage(amount);
countWhoPassed = countPassed(amount);
printPassed = printWhoPassed(amount);
return 0;
}

int howManygrades()
{
int gradesAmount;
printf("How many grades do you want?n");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
}
}
while (gradesAmount < 0) {
printf("Sorry, this amount of numbers is too small for the array.");
scanf("%d", &gradesAmount);
while (gradesAmount > 10) {
printf("Sorry, this amount of numbers is too big for the array.");
scanf("%d", &gradesAmount);
}
}

return gradesAmount;
}

void storesGrades(int amount)
{
int iterator;
float grade;
for (iterator = 0; iterator < amount; iterator++)
{

printf ("Enter another grade.");
scanf("%f", &grade);
while ((grade <= 0.0) || (grade > 10.0))
{
printf("Sorry, this number is not valid.");
scanf("%f", &grade);
}
grades[iterator] = grade;
}
}

void printAll(int amount)
{
int iterator;
for (iterator = 0; iterator < amount; iterator++)
{
printf("%.1fn", grades[iterator]);
}
}

int averageCalc(int amount)
{
float sum, averageResult, average;
int iterator;
sum = 0.0;
for (iterator = 0; iterator < amount; iterator++) {
sum += grades[iterator];
}
average = sum / (float)amount;
return average;
}

void printAverage(int amount)
{
float printThisAverage = averageCalc(amount);
printf("%.2f", printThisAverage);
}

int countPassed(int amount)
{
int iterator, countPassing;
countPassing = 0;
for (iterator = 0; iterator < amount; iterator++)
{
if (grades[iterator] >= 5.5)
{
countPassing++;
}
}
return countPassing;
}

int printWhoPassed(int amount)
{
int returnValue = countPassed(amount);
return returnValue;
}






c






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 11:38









Swordfish

8,95711335




8,95711335










asked Nov 21 '18 at 11:18









jjj

61




61












  • The message you get is a compilation error. You cannot run your code as it does not even compile. That set of code snippets is not a complete example or don't you use headers? See MCVE for details.
    – Gerhardh
    Nov 21 '18 at 11:27








  • 1




    Just guessing as too many details are missing: You might try to compile main without providing a prototype for that function.
    – Gerhardh
    Nov 21 '18 at 11:28










  • You don't declare the array grades in your code too
    – Chris Turner
    Nov 21 '18 at 11:38


















  • The message you get is a compilation error. You cannot run your code as it does not even compile. That set of code snippets is not a complete example or don't you use headers? See MCVE for details.
    – Gerhardh
    Nov 21 '18 at 11:27








  • 1




    Just guessing as too many details are missing: You might try to compile main without providing a prototype for that function.
    – Gerhardh
    Nov 21 '18 at 11:28










  • You don't declare the array grades in your code too
    – Chris Turner
    Nov 21 '18 at 11:38
















The message you get is a compilation error. You cannot run your code as it does not even compile. That set of code snippets is not a complete example or don't you use headers? See MCVE for details.
– Gerhardh
Nov 21 '18 at 11:27






The message you get is a compilation error. You cannot run your code as it does not even compile. That set of code snippets is not a complete example or don't you use headers? See MCVE for details.
– Gerhardh
Nov 21 '18 at 11:27






1




1




Just guessing as too many details are missing: You might try to compile main without providing a prototype for that function.
– Gerhardh
Nov 21 '18 at 11:28




Just guessing as too many details are missing: You might try to compile main without providing a prototype for that function.
– Gerhardh
Nov 21 '18 at 11:28












You don't declare the array grades in your code too
– Chris Turner
Nov 21 '18 at 11:38




You don't declare the array grades in your code too
– Chris Turner
Nov 21 '18 at 11:38












2 Answers
2






active

oldest

votes


















2














There seem to be a couple of problems. I think the error message you get is weird, it should instead say that countPassed is not defined. That's because you define it after you call it. You can fix it by adding a prototype for the function before you call it. This way you tell the compiler about the existence of a function (without defining the function yet) and it will compile. For me, it worked by adding the following prototypes to your code before the main:



int countPassed(int amount);
void printAll(int amount);
void printAverage(int amount);
void storesGrades(int amount);


Alternatively, you could just put the main function after all the other functions. Of course, that's not always going to be an option in real projects.



Furthermore, there's no definition for grades. I assume you want an array of int, so adding something like int grades[10] should do the trick (in this example that would work with a maximum of 10 grades, it's also possibly to dynamically allocate that memory to allow whatever amount the user wants).



Also, I had to add #include "stdio.h" to make it compile with the printf, although some compilers won't mind if it's missing.






share|improve this answer





























    2














    Since the first time you use the function countPassed is here:



    countWhoPassed = countPassed(amount);


    And the function is being defined much later, the compiler can't know yet how to treat a function like that. So since no prototype is declared yet, the compiler doesn't know that countPassed() returns an int. So without that information, the compiler assumes,



    countWhoPassed = countPassed(amount);


    is trying to assign the function pointer of countPassed(int) to the variable countWhoPassed. But then it figures that it also doesn't know such function.



    But how should the compiler know it better, not having seen this functions prototype yet?



    So make the compiler aware of how that function should look like before its first occurrence.



    So simply put



    int countPassed(int amount);


    in the declaration and include area so the compiler knows from there on how to treat that identifier.



    Or as an advanced option, declare it in a header file and include that one.



    Disclaimer: I haven't run the code nor checked it for other errors. I just answered that specific error you asked about.






    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410977%2fc-code-error-not-a-function-or-function-pointer%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      There seem to be a couple of problems. I think the error message you get is weird, it should instead say that countPassed is not defined. That's because you define it after you call it. You can fix it by adding a prototype for the function before you call it. This way you tell the compiler about the existence of a function (without defining the function yet) and it will compile. For me, it worked by adding the following prototypes to your code before the main:



      int countPassed(int amount);
      void printAll(int amount);
      void printAverage(int amount);
      void storesGrades(int amount);


      Alternatively, you could just put the main function after all the other functions. Of course, that's not always going to be an option in real projects.



      Furthermore, there's no definition for grades. I assume you want an array of int, so adding something like int grades[10] should do the trick (in this example that would work with a maximum of 10 grades, it's also possibly to dynamically allocate that memory to allow whatever amount the user wants).



      Also, I had to add #include "stdio.h" to make it compile with the printf, although some compilers won't mind if it's missing.






      share|improve this answer


























        2














        There seem to be a couple of problems. I think the error message you get is weird, it should instead say that countPassed is not defined. That's because you define it after you call it. You can fix it by adding a prototype for the function before you call it. This way you tell the compiler about the existence of a function (without defining the function yet) and it will compile. For me, it worked by adding the following prototypes to your code before the main:



        int countPassed(int amount);
        void printAll(int amount);
        void printAverage(int amount);
        void storesGrades(int amount);


        Alternatively, you could just put the main function after all the other functions. Of course, that's not always going to be an option in real projects.



        Furthermore, there's no definition for grades. I assume you want an array of int, so adding something like int grades[10] should do the trick (in this example that would work with a maximum of 10 grades, it's also possibly to dynamically allocate that memory to allow whatever amount the user wants).



        Also, I had to add #include "stdio.h" to make it compile with the printf, although some compilers won't mind if it's missing.






        share|improve this answer
























          2












          2








          2






          There seem to be a couple of problems. I think the error message you get is weird, it should instead say that countPassed is not defined. That's because you define it after you call it. You can fix it by adding a prototype for the function before you call it. This way you tell the compiler about the existence of a function (without defining the function yet) and it will compile. For me, it worked by adding the following prototypes to your code before the main:



          int countPassed(int amount);
          void printAll(int amount);
          void printAverage(int amount);
          void storesGrades(int amount);


          Alternatively, you could just put the main function after all the other functions. Of course, that's not always going to be an option in real projects.



          Furthermore, there's no definition for grades. I assume you want an array of int, so adding something like int grades[10] should do the trick (in this example that would work with a maximum of 10 grades, it's also possibly to dynamically allocate that memory to allow whatever amount the user wants).



          Also, I had to add #include "stdio.h" to make it compile with the printf, although some compilers won't mind if it's missing.






          share|improve this answer












          There seem to be a couple of problems. I think the error message you get is weird, it should instead say that countPassed is not defined. That's because you define it after you call it. You can fix it by adding a prototype for the function before you call it. This way you tell the compiler about the existence of a function (without defining the function yet) and it will compile. For me, it worked by adding the following prototypes to your code before the main:



          int countPassed(int amount);
          void printAll(int amount);
          void printAverage(int amount);
          void storesGrades(int amount);


          Alternatively, you could just put the main function after all the other functions. Of course, that's not always going to be an option in real projects.



          Furthermore, there's no definition for grades. I assume you want an array of int, so adding something like int grades[10] should do the trick (in this example that would work with a maximum of 10 grades, it's also possibly to dynamically allocate that memory to allow whatever amount the user wants).



          Also, I had to add #include "stdio.h" to make it compile with the printf, although some compilers won't mind if it's missing.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 11:32









          Blaze

          4,5021628




          4,5021628

























              2














              Since the first time you use the function countPassed is here:



              countWhoPassed = countPassed(amount);


              And the function is being defined much later, the compiler can't know yet how to treat a function like that. So since no prototype is declared yet, the compiler doesn't know that countPassed() returns an int. So without that information, the compiler assumes,



              countWhoPassed = countPassed(amount);


              is trying to assign the function pointer of countPassed(int) to the variable countWhoPassed. But then it figures that it also doesn't know such function.



              But how should the compiler know it better, not having seen this functions prototype yet?



              So make the compiler aware of how that function should look like before its first occurrence.



              So simply put



              int countPassed(int amount);


              in the declaration and include area so the compiler knows from there on how to treat that identifier.



              Or as an advanced option, declare it in a header file and include that one.



              Disclaimer: I haven't run the code nor checked it for other errors. I just answered that specific error you asked about.






              share|improve this answer


























                2














                Since the first time you use the function countPassed is here:



                countWhoPassed = countPassed(amount);


                And the function is being defined much later, the compiler can't know yet how to treat a function like that. So since no prototype is declared yet, the compiler doesn't know that countPassed() returns an int. So without that information, the compiler assumes,



                countWhoPassed = countPassed(amount);


                is trying to assign the function pointer of countPassed(int) to the variable countWhoPassed. But then it figures that it also doesn't know such function.



                But how should the compiler know it better, not having seen this functions prototype yet?



                So make the compiler aware of how that function should look like before its first occurrence.



                So simply put



                int countPassed(int amount);


                in the declaration and include area so the compiler knows from there on how to treat that identifier.



                Or as an advanced option, declare it in a header file and include that one.



                Disclaimer: I haven't run the code nor checked it for other errors. I just answered that specific error you asked about.






                share|improve this answer
























                  2












                  2








                  2






                  Since the first time you use the function countPassed is here:



                  countWhoPassed = countPassed(amount);


                  And the function is being defined much later, the compiler can't know yet how to treat a function like that. So since no prototype is declared yet, the compiler doesn't know that countPassed() returns an int. So without that information, the compiler assumes,



                  countWhoPassed = countPassed(amount);


                  is trying to assign the function pointer of countPassed(int) to the variable countWhoPassed. But then it figures that it also doesn't know such function.



                  But how should the compiler know it better, not having seen this functions prototype yet?



                  So make the compiler aware of how that function should look like before its first occurrence.



                  So simply put



                  int countPassed(int amount);


                  in the declaration and include area so the compiler knows from there on how to treat that identifier.



                  Or as an advanced option, declare it in a header file and include that one.



                  Disclaimer: I haven't run the code nor checked it for other errors. I just answered that specific error you asked about.






                  share|improve this answer












                  Since the first time you use the function countPassed is here:



                  countWhoPassed = countPassed(amount);


                  And the function is being defined much later, the compiler can't know yet how to treat a function like that. So since no prototype is declared yet, the compiler doesn't know that countPassed() returns an int. So without that information, the compiler assumes,



                  countWhoPassed = countPassed(amount);


                  is trying to assign the function pointer of countPassed(int) to the variable countWhoPassed. But then it figures that it also doesn't know such function.



                  But how should the compiler know it better, not having seen this functions prototype yet?



                  So make the compiler aware of how that function should look like before its first occurrence.



                  So simply put



                  int countPassed(int amount);


                  in the declaration and include area so the compiler knows from there on how to treat that identifier.



                  Or as an advanced option, declare it in a header file and include that one.



                  Disclaimer: I haven't run the code nor checked it for other errors. I just answered that specific error you asked about.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 21 '18 at 11:46









                  dhein

                  4,08042360




                  4,08042360






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53410977%2fc-code-error-not-a-function-or-function-pointer%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Wiesbaden

                      Marschland

                      Dieringhausen