Simple GradeSystem
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 37

Thread: Simple GradeSystem

  1. #1
    Join Date
    Jul 2010
    Posts
    13

    Question Simple GradeSystem

    Hello,
    New here and hope to stay. Anyways...

    I have started back with C++ and wanted to see how much I remembered. So please tell me what I am doing wrong. I am on linux at the moment and could not remeber if you used <iostream> with windows or linux.

    Also need explanations on what do, I believe one of the main problems with my code is I need to keep the variables in ( ).

    Code:

    #include <iostream>
    #include <fstream> // open, read, and write files

    //for time
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    using namespace std;

    void writeGrade(int studentAverage, int letterGrade){
    /*
    Use the variable gradeAverage to determin the the grade was a A, B, C, D, or F. Then open of the person's file, and write the grade.
    */
    findLetter();
    ofstream gradeFile;
    gradeFile.open ("grades.txt");
    gradeFile << "Student: " << studentAverage << endl;
    gradeFile << "Grade: " << letterGrade << endl;
    gradeFile << "Average: " << studentAverage << endl << endl;
    }

    int theAverage(int totalAmount, int gradeNumber, int studentAverage){
    /*
    Here we will average all the numbers together inside of a for loop
    */
    totalAmount / gradeNumber == studentAverage;
    return studentAverage;
    }

    int findLetter(){
    //take the number and find the letter it is == to
    //then store that letter in letterGrade
    if ( studentAverage > 95 ){
    letterGrade == A;
    }
    if ( studentAverage > 85 ){
    letterGrade == B;
    }
    if ( studentAverage > 80 ){
    letterGrade == C;
    }
    if ( studentAverage > 75 ){
    letterGrade == D;
    }
    if ( studentAverage < 69 ){
    letterGrade == F;
    }
    return letterGrade;
    }

    void saveError(){
    // save error in log.txt
    nowTime(int theTime);
    ofstream logFile;
    logFile.open ("log.txt");
    logFile << "Date: " << theTime << endl;
    logFile << "Error: File does not exist or cannot be opened." << endl;
    logFile << "Please create file, or create a new file." << endl << endl;
    }

    int nowTime(){

    time_t now;
    time(&now);

    theTime = "%s", ctime(&now);

    return theTime;
    }

    int main(){
    //startup variables that we will use
    char studentName[255];
    int studentAverage;
    int gradeNumber; // amount of student Averages
    int totalAmount; //will hold all averages
    int submitAmount; //amount submited during for loop session
    char letterGrade; // will store the lettergrade before it is written to grades.txt
    int theTime; // will hold the current time
    bool canWe; // asks if we can continue


    // find out who we will be grading
    cout << "Hello user!" << endl;
    cout << "This program lets you average the grade of your student and write there grade in a text file." << endl;
    cout << "Who will be writting a grade for today?" << endl << "Name: ";
    cin >> studentName >> endl;
    cout << "Ok, we will be grading " << studentName << "today!" << endl;

    // make a loop for finding out the average
    for ( gradeNumber; canWe == true; gradeNumber++; ){
    cout << "Please submit the next grade." << endl << "Grade: ";
    cin >> submitAmount;
    submitAmount + totalAmount = totalAmount;
    cout << "Thank you, the grade has been added." << endl;
    cout << "Would you like to add another grade or would you like to quite?" << endl;
    cout << "Type 1 to contine or type 2 to quite and press <enter>." << endl << "1 or 0: "; // may need to be switched to true or false
    cin >> canWe >> endl;
    return totalAmount, gradeNumber;
    }

    theAverage();
    writeGrade();


    return 0;
    }

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,097

    Re: Simple GradeSystem

    I didn't look at the whole thing, but let's just look at this.
    Code:
    if ( studentAverage > 95 ){
    letterGrade == A;
    }
    if ( studentAverage > 85 ){
    letterGrade == B;
    }
    if ( studentAverage > 80 ){
    letterGrade == C;
    }
    if ( studentAverage > 75 ){
    letterGrade == D;
    }
    if ( studentAverage < 69 ){
    letterGrade == F;
    }
    Assume studentAverage is 96.

    The first test is true, so letterGrade gets assigned A.
    The second test is also true, so letterGrade no gets assigned a B, etc.

    letterGrade is defined in two places, one as an int and one as a char. A, B, C, etc. aren't defined anywhere. If you mean to use them as chars, wrap them in single quotes.

  3. #3
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,292

    Re: Simple GradeSystem

    Quote Originally Posted by GCDEF View Post
    I didn't look at the whole thing, but let's just look at this.
    Code:
    if ( studentAverage > 95 ){
    letterGrade == A;
    }
    if ( studentAverage > 85 ){
    letterGrade == B;
    }
    if ( studentAverage > 80 ){
    letterGrade == C;
    }
    if ( studentAverage > 75 ){
    letterGrade == D;
    }
    if ( studentAverage < 69 ){
    letterGrade == F;
    }
    Assume studentAverage is 96.

    The first test is true, so letterGrade gets assigned A.
    The second test is also true, so letterGrade no gets assigned a B, etc.

    letterGrade is defined in two places, one as an int and one as a char. A, B, C, etc. aren't defined anywhere. If you mean to use them as chars, wrap them in single quotes.
    May I add that none of those are actually assignements? They are all just equality operators, and hence, do nothing. You want "=" not "=="

    ...

    The funny part is that people usually mess up the other way:
    Code:
    if (i = 5) //always true
    {
        ...
    }
    Is your question related to IO?
    Read this C++ FAQ LITE article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  4. #4
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Simple GradeSystem

    And, remove one of the '=' signs:
    Code:
    if ( studentAverage > 95 ){
    letterGrade = 'A';
    }
    Viggy

  5. #5
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: Simple GradeSystem

    Code:
    totalAmount / gradeNumber == studentAverage;
    I think what you meant was
    Code:
    studentAverage = totalAmount / gradeNumber;
    Assignment always goes right-to-left. Note also that every variable here is an integer, which might not be what you want.

  6. #6
    Join Date
    Jul 2010
    Posts
    13

    Re: Simple GradeSystem

    thank you all so far, made changes

    Errors:
    Code:
    root@bt:~/gradesystem# make gradeSystem
    g++     gradeSystem.cpp   -o gradeSystem
    gradeSystem.cpp: In function 'void writeGrade(int, int)':
    gradeSystem.cpp:17: error: 'findLetter' was not declared in this scope
    gradeSystem.cpp: In function 'int findLetter()':
    gradeSystem.cpp:36: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:37: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:37: error: 'A' was not declared in this scope
    gradeSystem.cpp:39: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:40: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:40: error: 'B' was not declared in this scope
    gradeSystem.cpp:42: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:43: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:43: error: 'C' was not declared in this scope
    gradeSystem.cpp:45: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:46: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:46: error: 'D' was not declared in this scope
    gradeSystem.cpp:48: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:49: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:49: error: 'F' was not declared in this scope
    gradeSystem.cpp:51: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp: In function 'void saveError()':
    gradeSystem.cpp:56: error: expected primary-expression before 'int'
    gradeSystem.cpp:56: error: 'nowTime' was not declared in this scope
    gradeSystem.cpp:59: error: 'theTime' was not declared in this scope
    gradeSystem.cpp: In function 'int nowTime()':
    gradeSystem.cpp:69: error: 'theTime' was not declared in this scope
    gradeSystem.cpp: In function 'int main()':
    gradeSystem.cpp:90: error: no match for 'operator>>' in 'std::operator>> [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>](((std::basic_istream<char, std::char_traits<char> >&)(& std::cin)), ((char*)(& studentName))) >> std::endl'
    /usr/include/c++/4.3/istream:123: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:127: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:134: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:170: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:174: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:177: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:181: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:188: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:192: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:197: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:201: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:206: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:210: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:214: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:218: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:242: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:748: note:                 std::basic_istream<_CharT2, _Traits2>& std::operator>>(std::basic_istream<_CharT2, _Traits2>&, _CharT2*) [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/bits/istream.tcc:858: note:                 std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&) [with _CharT = char, _Traits = std::char_traits<char>]
    gradeSystem.cpp:94: error: expected `)' before ';' token
    gradeSystem.cpp:94: error: expected primary-expression before ')' token
    gradeSystem.cpp:94: error: expected `;' before ')' token
    gradeSystem.cpp:25: error: too few arguments to function 'int theAverage(int, int, int)'
    gradeSystem.cpp:105: error: at this point in file
    gradeSystem.cpp:13: error: too few arguments to function 'void writeGrade(int, int)'
    gradeSystem.cpp:106: error: at this point in file
    make: *** [gradeSystem] Error 1
    here is the new code:
    Code:
    #include <iostream>
    #include <fstream> // open, read, and write files
    
    //for time
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    using namespace std;
    
    void writeGrade(int studentAverage, int letterGrade){
    /*
    Use the variable gradeAverage to determin the the grade was a A, B, C, D, or F. Then open of the person's file, and write the grade.
    */
      findLetter();
      ofstream gradeFile;
      gradeFile.open ("grades.txt");
      gradeFile << "Student: " << studentAverage << endl;
      gradeFile << "Grade: " << letterGrade << endl;
      gradeFile << "Average: " << studentAverage << endl << endl;
    }
    
    int theAverage(int totalAmount, int gradeNumber, int studentAverage){
    /*
    Here we will average all the numbers together inside of a for loop
    */
      studentAverage = totalAmount / gradeNumber;
      return studentAverage;
    }
    
    int findLetter(){
    //take the number and find the letter it is == to
    //then store that letter in letterGrade
      if ( studentAverage > 95 ){
      letterGrade = A;
      }
      if ( 95 > studentAverage > 85 ){
      letterGrade = B;
      }
      if ( 85 > studentAverage > 80 ){
      letterGrade = C;
      }
      if ( 80 > studentAverage > 69 ){
      letterGrade = D;
      }
      if ( studentAverage < 69 ){
      letterGrade = F;
      }
      return letterGrade;
    }
    
    void saveError(){
    // save error in log.txt
      nowTime(int theTime);
      ofstream logFile;
      logFile.open ("log.txt");
      logFile << "Date: " << theTime << endl;
      logFile << "Error: File does not exist or cannot be opened." << endl;
      logFile << "Please create file, or create a new file." << endl << endl;
    }
    
    int nowTime(){
    
      time_t now;
      time(&now);
    
      theTime = "%s", ctime(&now);
    
    return theTime;
    }
    
    int main(){
      //startup variables that we will use
      char studentName[255];
      int studentAverage;
      int gradeNumber; // amount of student Averages
      int totalAmount; //will hold all averages
      int submitAmount; //amount submited during for loop session
      char letterGrade; // will store the lettergrade before it is written to grades.txt
      int theTime; // will hold the current time
      bool canWe; // asks if we can continue
      
    
      // find out who we will be grading
      cout << "Hello user!" << endl;
      cout << "This program lets you average the grade of your student and write there grade in a text file." << endl;
      cout << "Who will be writting a grade for today?" << endl << "Name: ";
      cin >> studentName >> endl;
      cout << "Ok, we will be grading " << studentName << "today!" << endl;
    
      // make a loop for finding out the average
      for ( gradeNumber; canWe == true; gradeNumber++; ){
      cout << "Please submit the next grade." << endl << "Grade: ";
      cin >> submitAmount;
      submitAmount + totalAmount = totalAmount;
      cout << "Thank you, the grade has been added." << endl;
      cout << "Would you like to add another grade or would you like to quite?" << endl;
      cout << "Type 1 to contine or type 2 to quite and press <enter>." << endl << "1 or 0: "; // may need to be switched to true or false
      cin >> canWe >> endl;
      return totalAmount, gradeNumber;
      }
    
      theAverage();
      writeGrade();
      
    
    return 0;
    }
    Will be working though this myself to see what I can do, but any help is appreciated.

  7. #7
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Simple GradeSystem

    Here an implementation of the findLetter which doesn't use an if/elseif cascade.

    Code:
    char findLetter(int grade)
    {
        // put the ranges to an array
        static int grades[] = { 69, 75, 80, 85, 90, 95 };
    
        // init return value
        char letter = 'A';
        // get number of elements
        int nGrades = sizeof(grades)/sizeof(grades[0]);
    
        // now check the ranges by a loop 
        for (int i = 0; i < nGrades; ++i)
        {
            // if the grade given is below we are done
            if (grade <= grades[i]) 
            {
                // grade character can be calculated from index 
                letter = 'A' + (char)(nGrades-1 - i);  // F for i==0, E for i==1, ...
                break;
            }
        }
        return letter;
    }
    Regards, Alex

  8. #8
    Join Date
    Jul 2010
    Posts
    13

    Re: Simple GradeSystem

    Quote Originally Posted by itsmeandnobodyelse View Post
    Here an implementation of the findLetter which doesn't use an if/elseif cascade.

    Code:
    char findLetter(int grade)
    {
        // put the ranges to an array
        static int grades[] = { 69, 75, 80, 85, 90, 95 };
    
        // init return value
        char letter = 'A';
        // get number of elements
        int nGrades = sizeof(grades)/sizeof(grades[0]);
    
        // now check the ranges by a loop 
        for (int i = 0; i < nGrades; ++i)
        {
            // if the grade given is below we are done
            if (grade <= grades[i]) 
            {
                // grade character can be calculated from index 
                letter = 'A' + (char)(nGrades-1 - i);  // F for i==0, E for i==1, ...
                break;
            }
        }
        return letter;
    }
    Regards, Alex
    I am gonna be honnest with you, that makes no sense... i don't see how that would even work... much less help me

  9. #9
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,097

    Re: Simple GradeSystem

    Quote Originally Posted by itsmeandnobodyelse View Post
    Here an implementation of the findLetter which doesn't use an if/elseif cascade.

    Code:
    char findLetter(int grade)
    {
        // put the ranges to an array
        static int grades[] = { 69, 75, 80, 85, 90, 95 };
    
        // init return value
        char letter = 'A';
        // get number of elements
        int nGrades = sizeof(grades)/sizeof(grades[0]);
    
        // now check the ranges by a loop 
        for (int i = 0; i < nGrades; ++i)
        {
            // if the grade given is below we are done
            if (grade <= grades[i]) 
            {
                // grade character can be calculated from index 
                letter = 'A' + (char)(nGrades-1 - i);  // F for i==0, E for i==1, ...
                break;
            }
        }
        return letter;
    }
    Regards, Alex
    Not sure I really see the advantage to that. It doesn't save any lines of code, isn't any more efficient and is less readable.

  10. #10
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Simple GradeSystem

    Quote Originally Posted by Zeveso View Post
    Hello,
    New here and hope to stay. Anyways...
    What grade does the student get if he gets a 70? Your attempt does not show what happens if the grade is between 70 and 75.

    Regards,

    Paul McKenzie

  11. #11
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,097

    Re: Simple GradeSystem

    Quote Originally Posted by Zeveso View Post
    if ( studentAverage > 95 ){
    letterGrade = A;
    }
    if ( 95 > studentAverage > 85 ){
    letterGrade = B;
    }
    if ( 85 > studentAverage > 80 ){
    letterGrade = C;
    }
    if ( 80 > studentAverage > 69 ){
    letterGrade = D;
    }
    if ( studentAverage < 69 ){
    letterGrade = F;
    }
    return letterGrade;
    }
    That still isn't optimal. You were closer the first time. Just use else between the if statements so that when one matches, the others are bypassed.

  12. #12
    Join Date
    Jul 2010
    Posts
    13

    Re: Simple GradeSystem

    Code:
    #include <iostream>
    #include <fstream> // open, read, and write files
    
    //for time
    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>
    
    using namespace std;
    
    void writeGrade(int studentAverage, int letterGrade){
    /*
    Use the variable gradeAverage to determin the the grade was a A, B, C, D, or F. Then open of the person's file, and write the grade.
    */
      findLetter();
      ofstream gradeFile;
      gradeFile.open ("grades.txt");
      gradeFile << "Student: " << studentAverage << endl;
      gradeFile << "Grade: " << letterGrade << endl;
      gradeFile << "Average: " << studentAverage << endl << endl;
    }
    
    int theAverage(int totalAmount, int gradeNumber, int studentAverage){
    /*
    Here we will average all the numbers together inside of a for loop
    */
      studentAverage = totalAmount / gradeNumber;
      return studentAverage;
    }
    
    int findLetter(){
    //take the number and find the letter it is == to
    //then store that letter in letterGrade
      if ( studentAverage > 95 ){
      letterGrade = A;
      }
      if ( 95 > studentAverage > 85 ){
      letterGrade = B;
      }
      if ( 85 > studentAverage > 80 ){
      letterGrade = C;
      }
      if ( 80 > studentAverage > 69 ){
      letterGrade = D;
      }
      if ( studentAverage < 69 ){
      letterGrade = F;
      }
      return letterGrade;
    }
    
    void saveError(){
    // save error in log.txt
      nowTime(int theTime);
      ofstream logFile;
      logFile.open ("log.txt");
      logFile << "Date: " << theTime << endl;
      logFile << "Error: File does not exist or cannot be opened." << endl;
      logFile << "Please create file, or create a new file." << endl << endl;
    }
    
    int nowTime(){
    
      time_t now;
      time(&now);
    
      theTime = "%s", ctime(&now);
    
    return theTime;
    }
    
    int main(){
      //startup variables that we will use
      char studentName[255];
      int studentAverage;
      int gradeNumber; // amount of student Averages
      int totalAmount; //will hold all averages
      int submitAmount; //amount submited during for loop session
      char letterGrade; // will store the lettergrade before it is written to grades.txt
      int theTime; // will hold the current time
      bool canWe; // asks if we can continue
      
    
      // find out who we will be grading
      cout << "Hello user!" << endl;
      cout << "This program lets you average the grade of your student and write there grade in a text file." << endl;
      cout << "Who will be writting a grade for today?" << endl << "Name: ";
      cin >> studentName >> endl;
      cout << "Ok, we will be grading " << studentName << "today!" << endl;
    
      // make a loop for finding out the average
      for ( gradeNumber; canWe == true; gradeNumber++; ){
      cout << "Please submit the next grade." << endl << "Grade: ";
      cin >> submitAmount;
      submitAmount + totalAmount = totalAmount;
      cout << "Thank you, the grade has been added." << endl;
      cout << "Would you like to add another grade or would you like to quite?" << endl;
      cout << "Type 1 to contine or type 2 to quite and press <enter>." << endl << "1 or 0: "; // may need to be switched to true or false
      cin >> canWe >> endl;
      return totalAmount, gradeNumber;
      }
    
      theAverage();
      writeGrade();
      
    
    return 0;
    }
    That is where I am at right now and I get the following errors...

    Code:
    root@bt:~/gradesystem# make gradeSystem
    g++     gradeSystem.cpp   -o gradeSystem
    gradeSystem.cpp: In function 'void writeGrade(int, int)':
    gradeSystem.cpp:17: error: 'findLetter' was not declared in this scope
    gradeSystem.cpp: In function 'int findLetter()':
    gradeSystem.cpp:36: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:37: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:37: error: 'A' was not declared in this scope
    gradeSystem.cpp:39: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:40: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:40: error: 'B' was not declared in this scope
    gradeSystem.cpp:42: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:43: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:43: error: 'C' was not declared in this scope
    gradeSystem.cpp:45: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:46: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:46: error: 'D' was not declared in this scope
    gradeSystem.cpp:48: error: 'studentAverage' was not declared in this scope
    gradeSystem.cpp:49: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp:49: error: 'F' was not declared in this scope
    gradeSystem.cpp:51: error: 'letterGrade' was not declared in this scope
    gradeSystem.cpp: In function 'void saveError()':
    gradeSystem.cpp:56: error: expected primary-expression before 'int'
    gradeSystem.cpp:56: error: 'nowTime' was not declared in this scope
    gradeSystem.cpp:59: error: 'theTime' was not declared in this scope
    gradeSystem.cpp: In function 'int nowTime()':
    gradeSystem.cpp:69: error: 'theTime' was not declared in this scope
    gradeSystem.cpp: In function 'int main()':
    gradeSystem.cpp:90: error: no match for 'operator>>' in 'std::operator>> [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>](((std::basic_istream<char, std::char_traits<char> >&)(& std::cin)), ((char*)(& studentName))) >> std::endl'
    /usr/include/c++/4.3/istream:123: note: candidates are: std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_istream<_CharT, _Traits>& (*)(std::basic_istream<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:127: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_ios<_CharT, _Traits>& (*)(std::basic_ios<_CharT, _Traits>&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:134: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::ios_base& (*)(std::ios_base&)) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:170: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(bool&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:174: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:177: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(short unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:181: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:184: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:188: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:192: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:197: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:201: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long long unsigned int&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:206: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(float&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:210: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:214: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(long double&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:218: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(void*&) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:242: note:                 std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::operator>>(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/istream:748: note:                 std::basic_istream<_CharT2, _Traits2>& std::operator>>(std::basic_istream<_CharT2, _Traits2>&, _CharT2*) [with _CharT2 = char, _Traits2 = std::char_traits<char>, _CharT = char, _Traits = std::char_traits<char>]
    /usr/include/c++/4.3/bits/istream.tcc:858: note:                 std::basic_istream<_CharT, _Traits>& std::operator>>(std::basic_istream<_CharT, _Traits>&, _CharT&) [with _CharT = char, _Traits = std::char_traits<char>]
    gradeSystem.cpp:94: error: expected `)' before ';' token
    gradeSystem.cpp:94: error: expected primary-expression before ')' token
    gradeSystem.cpp:94: error: expected `;' before ')' token
    gradeSystem.cpp:25: error: too few arguments to function 'int theAverage(int, int, int)'
    gradeSystem.cpp:105: error: at this point in file
    gradeSystem.cpp:13: error: too few arguments to function 'void writeGrade(int, int)'
    gradeSystem.cpp:106: error: at this point in file
    make: *** [gradeSystem] Error 1

  13. #13
    Join Date
    Apr 1999
    Posts
    27,427

    Re: Simple GradeSystem

    Code:
      if ( 95 > studentAverage > 85 ){
    C++ isn't math. You do not compare if a value is in between two values this way.
    Code:
    if ( studentAverage > 85 && studentAverage < 95)
    That is how you compare if something is in betwen two numbers.

    Secondly, you didn't answer my original question: What grade does the student get if he/she gets a 70?

    Regards,

    Paul McKenzie

  14. #14
    Join Date
    Jul 2010
    Posts
    13

    Re: Simple GradeSystem

    Quote Originally Posted by Paul McKenzie View Post
    Code:
      if ( 95 > studentAverage > 85 ){
    C++ isn't math. You do not compare if a value is in between two values this way.
    Code:
    if ( studentAverage > 85 && studentAverage < 95)
    That is how you compare if something is in betwen two numbers.

    Secondly, you didn't answer my original question: What grade does the student get if he/she gets a 70?

    Regards,

    Paul McKenzie
    Suppose to be a "D", but have not gotten there... just trying to get it to compile. Haha...

  15. #15
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,097

    Re: Simple GradeSystem

    You have a lot of problems. Starting at the beginning, at the time you're using it, the compiler hasn't seen findLetter, so it doesn't know what it is. Move it before main.

    studentAverage is declared in main, yet you're trying to use it in findLetter. You'll need to pass it to findLetter as an argument. Same with letterGrade.

    I explained the problem with A, B, C, etc earlier in the thread.

    Not sure what you're trying to do in the first line of saveError.

    In this for loop
    Code:
      for ( gradeNumber; canWe == true; gradeNumber++; )
      {
    	  cout << "Please submit the next grade." << endl << "Grade: ";
    	  cin >> submitAmount;
    	  submitAmount + totalAmount = totalAmount;
    	  cout << "Thank you, the grade has been added." << endl;
    	  cout << "Would you like to add another grade or would you like to quite?" << endl;
    	  cout << "Type 1 to contine or type 2 to quite and press <enter>." << endl << "1 or 0: "; // may need to be switched to true or false
    	  cin >> canWe >> endl;
    	  return totalAmount, gradeNumber;
      }
    What are you trying to do with gradeNumber?
    You have an unconditional return in the loop.
    You can only return one value.
    Your function calls after the loop won't be executed because of the return in the for loop.

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center