Input int score then get grade???


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Input int score then get grade???

  1. #1
    Join Date
    Dec 2007
    Posts
    2

    Input int score then get grade???

    Code:
    /* This program reads a test score, calculates the letter
     grade for the score, and prints the grade.
    */
    #include <iostream>
    
    using namespace std;
    
    char studentScore (int score);
    
    int main ()
    
    {
     cout << "Enter the test score (0-100): ";
     int  score;
     cin  >> score;
     char grade = studentScore (grade);
     cout << "The grade is: " << grade << endl;
      
        cout << "\n\n\n";
        system("pause");
        return 0;
    }
    
    /* ===================== studentScore =====================
     This function calculates the letter grade for a score.
        Pre    the parameter score
        Post   Returns the grade
    */
    
    char studentScore (int score)
    {
     int  temp = score / 100;
     char grade;
     switch (temp)
        {
         case 100 : grade = 'A Plus!';
                   break;
         case  90 : grade = 'A';
                   break;
         case  80 : grade = 'B';
                   break;
         case  70 : grade = 'C';
                   break;
         case  60 : grade = 'D';
                   break;
         default : grade = 'F';
        } // switch
     return grade;
    }
    WHAT AM I DOING WRONG HERE???

  2. #2
    Join Date
    Dec 2007
    Posts
    16
    I think this will solve your problem. Take note that the function studentScore() will eventually return the string "A Plus!" (which is not of type char, but char*):


    /* This program reads a test score, calculates the letter
    grade for the score, and prints the grade.
    */
    #include <iostream>

    using namespace std;

    char *studentScore (int score);

    int main ()

    {
    cout << "Enter the test score (0-100): ";
    int score;
    cin >> score;
    char *grade = studentScore (score);
    cout << "The grade is: " << grade << endl;

    cout << "\n\n\n";
    system("pause");
    return 0;
    }

    /* ===================== studentScore =====================
    This function calculates the letter grade for a score.
    Pre the parameter score
    Post Returns the grade
    */

    char *studentScore (int score)
    {
    char *grade;

    if (score == 100)
    grade = "A Plus!";
    else if (score >= 90)
    grade = "A";
    else if (score >= 80)
    grade = "B";
    else if (score >= 70)
    grade = "C";
    else if (score >= 60)
    grade = "D";
    else
    grade = "F";

    return grade;
    }
    Last edited by watdg; 12-10-2007 at 01:36 AM.

Similar Threads

  1. Replies: 0
    Last Post: 03-18-2007, 03:25 PM
  2. No
    By chintucs in forum Java
    Replies: 2
    Last Post: 01-21-2007, 05:08 PM
  3. Typedef Declaration in VB
    By floydus in forum VB Classic
    Replies: 7
    Last Post: 06-05-2006, 06:49 PM
  4. Input string was not in a correct format
    By mdengler in forum ASP.NET
    Replies: 0
    Last Post: 11-26-2002, 03:32 PM
  5. INSERT for multiple tables with IDENTITY
    By Kay in forum Database
    Replies: 1
    Last Post: 07-04-2001, 06:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center