Thread: Input int score then get grade???

  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    4

    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
    Registered User
    Join Date
    Dec 2006
    Location
    Canada
    Posts
    3,229
    Code:
    char grade = studentScore (score);
    Code:
     int  temp = score / 100;
    what's that for?

    next time, give more details - what are u trying to do, what is it doing, along with all the errors and such.

  3. #3
    Registered User
    Join Date
    Nov 2005
    Posts
    673
    You cannot make a single char be a string.

    Use the C++ string type.
    Code:
    #include <string>
    
    std::string grade;
    
    grade = "A Plus!"; //notice the double quotes ("") instead of the ('')
    Good Luck.

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Code:
         case 100 : grade = 'A Plus!';
                   break;
    Lol.

    OK so learn the difference between char and char*.
    Then just use std::string. This is C++ and not C, after all.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 07:45 AM
  4. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 12:36 PM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 04:28 AM