Connecting Tech Pros Worldwide Forums | Help | Site Map

Help with code

Member
 
Join Date: Jan 2007
Posts: 32
#1: Feb 1 '07
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.

Expand|Select|Wrap|Line Numbers
  1. #include<iostream>
  2. using namespace std;
  3. int main() {
  4.  int countScores = 0;
  5.  int sumScores = 0; 
  6.  cout <<"Enter score"<< endl;
  7.  int n = 0;
  8.  cin>>n;
  9.  
  10. funct average(int score1, score2, score3)
  11. {
  12.     cout<< “Enter score1”<<endl;
  13.     cout<<”Enter score2”<<endl;
  14.     cout<<”Enter score3”<<endl;
  15.  
  16. average = (score1 + score2 + score3)/3;
  17.  
  18. return average;
  19. }
  20.  
  21.  
  22.  
  23.  while(n >= 0) {
  24.   sumScores = sumScores + n;
  25.   countScores++;
  26.   cin>>n;
  27.  }
  28.  cout<<"You entered "<<countScores<<" numbers"<<endl;
  29.  cout<<"Their sum is :"<<sumScores<<endl;
  30.  cout << “The average score is:”<<endl;
  31.  
  32.  return 0;
  33. }

Ganon11's Avatar
Moderator
 
Join Date: Oct 2006
Location: New York, United States of America
Posts: 3,428
#2: Feb 1 '07

re: Help with code


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
Reply