Advertisement
satriafu5710

Menghitung Nilai Rata-rata Pelajaran Tiap Siswa C++

Nov 28th, 2021
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.  
  7.     int n, m, i, j;
  8.     string nama;
  9.     float nilai, jumlah, rerata;
  10.  
  11.     cout << "\n\t Hitung Nilai Rata-rata Pelajaran Tiap Siswa \n\n";
  12.  
  13.     cout << " Jumlah Siswa : ";
  14.     cin >> n;
  15.  
  16.     cout << " Jumlah MP    : ";
  17.     cin >> m;
  18.  
  19.     i = 1;
  20.  
  21.     while (i <= n)
  22.     {
  23.         cout << "\n Nama Siswa " << i << " : ";
  24.         cin >> nama;
  25.  
  26.         j = 1;
  27.         jumlah = 0;
  28.  
  29.         while (j <= m)
  30.         {
  31.             cout << " Nilai MP " << j << "   : ";
  32.             cin >> nilai;
  33.  
  34.             jumlah = jumlah + nilai;
  35.  
  36.             j = j + 1;
  37.         }
  38.  
  39.         rerata = jumlah / m;
  40.  
  41.         cout << "\n Rata-rata Nilai " << nama << " : " << rerata;
  42.         cout << endl;
  43.  
  44.         i = i + 1;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement