Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int getScores(int[]);
- int countPerfect(int[],int);
- int main(){
- int score[20], valid, valid_scores = 0;
- cout<<"This program will allow you to enter up to 20 scores"<<endl;
- cout<<"and will then report how many perfect scores were entered."<<endl;
- valid_scores = getScores(score);
- valid = countPerfect(score,valid_scores);
- cout<<"the "<<valid_scores<<" you entered include "<<valid<<" perfect scores"<<endl;
- }
- int getScores(int score[20]){
- int valid_score = 0;
- for(int i=0; i< 20; i++){
- cout << "\nEnter a score 0 - 100 (or -1 to quit):"<<endl;
- cin >> score[i];
- if(score[i] == -1){
- break;
- }
- else if(score[i]<0 || score[i]>100){
- cout<<"Invalid score. Scores may not be greater than 100.\n"<<endl;
- }
- else{
- valid_score++;
- }
- }
- return valid_score;
- }
- int countPerfect(int score[20],int valid){
- int perfect_score = 0;
- for(int j = 0; j < valid; j++){
- if(score[j] == 100){
- perfect_score++;
- }
- }
- return perfect_score;
- }
Advertisement
Add Comment
Please, Sign In to add comment