wcypierre

getscores

Nov 24th, 2011
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int getScores(int[]);
  6. int countPerfect(int[],int);
  7.  
  8. int main(){
  9.     int score[20], valid, valid_scores = 0;
  10.  
  11.     cout<<"This program will allow you to enter up to 20 scores"<<endl;
  12.     cout<<"and will then report how many perfect scores were entered."<<endl;
  13.  
  14.     valid_scores = getScores(score);
  15.     valid = countPerfect(score,valid_scores);
  16.     cout<<"the "<<valid_scores<<" you entered include "<<valid<<" perfect scores"<<endl;
  17. }
  18.  
  19. int getScores(int score[20]){
  20.     int valid_score = 0;
  21.     for(int i=0; i< 20; i++){
  22.         cout << "\nEnter a score 0 - 100 (or -1 to quit):"<<endl;
  23.         cin  >> score[i];
  24.  
  25.         if(score[i] == -1){
  26.  
  27.             break;
  28.         }
  29.         else if(score[i]<0 || score[i]>100){
  30.             cout<<"Invalid score. Scores may not be greater than 100.\n"<<endl;
  31.         }
  32.         else{
  33.             valid_score++;
  34.         }
  35.     }
  36.     return valid_score;
  37. }
  38.  
  39. int countPerfect(int score[20],int valid){
  40.     int perfect_score = 0;
  41.  
  42.     for(int j = 0; j < valid; j++){
  43.         if(score[j] == 100){
  44.             perfect_score++;
  45.         }
  46.     }
  47.     return perfect_score;
  48. }
  49.  
  50.  
Advertisement
Add Comment
Please, Sign In to add comment