Created
November 10, 2021 01:46
-
-
Save Sanokei/37c672bc77af3ca2e04c97208bc252fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using namespace std; | |
/* | |
Write a program that reads-in 10 student names with their grades, then print the student names of those who got a grade higher than the average. | |
*/ | |
int main(){ | |
int grade[10]; | |
string name[10]; | |
float total = 0; | |
float average; | |
int counter = 0; | |
int counter2 = 0; | |
for (int i = 0; i < 10; i++) | |
{ | |
cout << "Enter name: "; | |
cin >> name[i]; | |
cout << "Enter grade: "; | |
cin >> grade[i]; | |
total = total + grade[i]; | |
counter++; | |
} | |
average = total / counter; | |
cout << endl; | |
cout << "The average is: " << average << endl; | |
cout << endl; | |
for (int i = 0; i < 10; i++) | |
{ | |
if (grade[i] > average) | |
{ | |
counter2++; | |
cout << name[i] << " got a grade higher than the average" << endl; | |
} | |
} | |
if (counter2 == 0) | |
{ | |
cout << "Everyone got a grade lower than the average" << endl; | |
} | |
return 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment