SHARE
TWEET

Untitled

a guest Sep 19th, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. int main()
  5. {
  6.     std::string progName = "Grade Analysis";
  7.     std::cout << "Welcome to the " << progName << " program\n"
  8.               << "How many students to be entered (max 10)? " << std::endl;
  9.    
  10.     int studentNum;
  11.     float averageGrade;
  12.  
  13.     std::cin >> studentNum;
  14.  
  15.     if (studentNum > 10) {
  16.         std::cout << "Too many students - up to 10 only allowed" << std::endl;
  17.         exit(0);
  18.     }
  19.  
  20.     std::string names[10]; // allows up to 10 names t be stored
  21.     int grades[10];
  22.     for (int i=0;i<studentNum;i++) {
  23.         std::cout << "Enter name for student " << (i+1) << " : ";
  24.         std::string studentName;
  25.         std::cin >> studentName;
  26.         names[i] = studentName;
  27.         std::cout << "Enter " << studentName << "'s grade: ";
  28.         int grade;
  29.         std::cin >> grade;
  30.         grades[i] = grade;
  31.     }
  32.  
  33.     // calculate average
  34.  
  35.     int sum = 0;
  36.     for (int i = 0; i < studentNum; i++) {
  37.         sum = sum + grades[i];
  38.     }
  39.     float average = static_cast<float>(sum) / studentNum;
  40.  
  41.     std::cout << "Average grade is " << average << std::endl;
  42.  
  43.     std::cout << progName << " completed" << std::endl;
  44.     exit(0);
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top