Call Functions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CStrickland
    New Member
    • Nov 2008
    • 1

    Call Functions

    #include <iostream>

    void Lab11identifica tion()
    {

    }

    int getNumericGrade (int gradeIn) {



    do {

    if (gradeIn > 100 || gradeIn < 0 && gradeIn != -1)
    cout << "Number out of range. Try again." << endl;
    else cout<<"Your letter grade is: "<< getLetterGrade (gradeIn)<<endl ;

    cout << "Enter a numeric grade (0-100, -1 to stop): ";
    cin >> gradeIn;

    } while (gradeIn != -1);
    if (gradeIn == -1)
    cout<<"Good-Bye";


    return gradeIn;
    }


    char getLetterGrade (int gradeIn) {
    char Lgrade;
    if (gradeIn <= 100 && gradeIn >=90)
    Lgrade='A';
    if (gradeIn <90 && gradeIn >=80)
    Lgrade='B';
    if (gradeIn <80 && gradeIn >=70)
    Lgrade='C';
    if (gradeIn <70 && gradeIn>=60)
    Lgrade='D';
    if (gradeIn <60 && gradeIn>0)
    Lgrade='F';
    cout<<Lgrade;
    return Lgrade;
    } // getLetterGrade


    int main() {
    char answer;
    int gradeIn;
    Lab11identifica tion();

    cout << "Enter a numeric grade (0-100, -1 to stop): ";
    cin >> gradeIn;
    getNumericGrade (gradeIn);





    return 0;
    } // main

    In the getNumericGrade function I need it to also print the letter grade how do I call to the function getLetterGrade correctly? I have been getting a compile error saying something about an implicit declaration of the function what does this mean?

    The output should be....

    Enter a numeric grade (0-100, -1 to stop): 120
    The grade is out of range; try again.

    Enter a numeric grade (0-100, -1 to stop): -6
    The grade is out of range; try again.

    Enter a numeric grade (0-100, -1 to stop): 84
    The letter grade is B

    Enter a numeric grade (0-100, -1 to stop): 77
    The letter grade is C

    Enter a numeric grade (0-100, -1 to stop): -1
    Good-bye
  • oler1s
    Recognized Expert Contributor
    • Aug 2007
    • 671

    #2
    In the getNumericGrade function I need it to also print the letter grade how do I call to the function getLetterGrade correctly? I have been getting a compile error saying something about an implicit declaration of the function what does this mean?
    Post the exact error (by copy pasting). Also, edit your post and put all the code in CODE tags. Anything code like (including console input or output) is best put in code tags.

    Comment

    • vmpstr
      New Member
      • Nov 2008
      • 63

      #3
      Compiler goes from top to bottom of a file as it is trying to compile your program. By the time it reaches a call to getLetterGrade in your getNumericGrade function, it hasn't seen any definitions or declarations of getLetterGrade, so it issues a warning (or an error).

      To solve this, either reorder your functions so that for any given function, all of the functions that it uses are defined above it.

      Another way (and in my opinion, a better way) would be to put the function prototypes for all your functions at the top of the file (after the includes)

      something like the following:

      Code:
      int getNumericGrade(int gradeIn);
      char getLetterGrade(int gradeIn);

      Comment

      Working...