Help with code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • compsci
    New Member
    • Jan 2007
    • 32

    Help with code

    I have most of my code I just need help with these last 2.

    3. Define a function validScore that, passed a score, returns true if the score is between 0 and 100 and otherwise returns false. Using this function, modify the loop that reads in the scores so that, if the score is not valid, it is echoed with a message saying that the score is invalid, and so that the score is counted and added to the sum only when it is valid. (Note that there is some redundancy as validScore is used here since the loop exits when a negative score is entered—so validScore is never passed a score that is invalid because it is negative.)
    4. Define a function letterGrade that, passed a valid score (one between 0 and 100), returns a letter grade according to the following schedule:
    ‘A’: 90 and above
    ‘B’: 80-89
    ‘C’: 70-79
    ‘D’: 60-69
    ‘F’: below 60
    Use this function to find the letter grade corresponding to each valid score and output the letter grade as soon as it is found. Keep a count of the number of each letter grade (‘A’-‘F’) and output each count at the end of the run.

    Code:
    #include<iostream>
    using namespace std;
    int main() {
     int countScores = 0;
     int sumScores = 0; 
     cout <<"Enter score"<< endl;
     int n = 0;
     cin>>n;
    
    funct average(int score1, score2, score3)
    {
    	cout<< “Enter score1”<<endl;
    	cout<<”Enter score2”<<endl;
    	cout<<”Enter score3”<<endl;
    
    average = (score1 + score2 + score3)/3;
    
    return average;
    }
    
    
    
     while(n >= 0) {
      sumScores = sumScores + n;
      countScores++;
      cin>>n;
     }
     cout<<"You entered "<<countScores<<" numbers"<<endl;
     cout<<"Their sum is :"<<sumScores<<endl;
     cout << “The average score is:”<<endl;
    
     return 0;
    }
  • Ganon11
    Recognized Expert Specialist
    • Oct 2006
    • 3651

    #2
    What work have you done on these 2 parts? What ideas do you have on solving them?

    Try starting by reading the problem specifications and pulling out the important information - for example, on part 4 you may note that:

    1) You need a function computeGrade
    2) This function will take a single integer parameter
    3) Its return type is char
    4) What character should be returned, based on the integer parameter

    Comment

    Working...