avv210

Program Menghitung Nilai IPS

Sep 28th, 2021 (edited)
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.15 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <chrono>
  4. #include <ctime>
  5.  
  6. #define jumlahMatkul 5
  7.  
  8. void makeLine( int len )
  9. {
  10.     for ( int i = 0; i < len; i++ )
  11.         printf( "=" );
  12.     printf("\n");
  13. }
  14.  
  15. void localTime()
  16. {
  17.     std::time_t time = std::chrono::system_clock::to_time_t( std::chrono::system_clock::now() );
  18.     struct std::tm* ptm = std::localtime( &time );
  19.     std::cout << "\t\t" << std::put_time( ptm, "%c" ) << "\n";
  20. }
  21.  
  22. int main()
  23. {
  24.     int sks = 0;
  25.     float totalSKS = 0;
  26.     float ips = 0;
  27.     float nilaiMatkul[jumlahMatkul];
  28.     float mutuMatkul[jumlahMatkul];
  29.     float totalMutu = 0;
  30.     std::string nama;
  31.     std::string nim;
  32.     std::string jurusan;
  33.  
  34.     makeLine(55);
  35.     printf( "\tProgram Menghitung Nilai IPS Mahasiswa\n" );
  36.     localTime();
  37.     makeLine(55);
  38.  
  39.     printf( "Masukkan Nama\t\t: " ); getline( std::cin, nama );
  40.     printf( "Masukkan NIM\t\t: " ); getline( std::cin, nim );
  41.     printf( "Masukkan Jurusan\t: " ); getline( std::cin, jurusan );
  42.  
  43.     makeLine(55);
  44.  
  45.     printf( "WARNING!\n" );
  46.     printf( "SKS hanya boleh angka 2 atau 4\n" );
  47.     printf( "Range nilai matkul hanya boleh angka 0 sampai 4\n" );
  48.  
  49.     makeLine(55);
  50.  
  51.     for ( int i = 0; i < jumlahMatkul; i++ )
  52.     {
  53.         printf( "Masukkan jumlah SKS matkul ke-%d\t: ", i+1 );
  54.         scanf("%d", &sks);
  55.  
  56.         if ( sks != 2 && sks != 4 )
  57.         {
  58.             printf("ERROR: SKS tidak sesuai dengan ketentuan!!\n");
  59.             break;
  60.         }
  61.        
  62.         printf( "Masukkan nilai matkul ke-%d\t: ", i+1 );
  63.         scanf( "%f", &nilaiMatkul[i] );
  64.  
  65.         if ( nilaiMatkul[i] < 0 || nilaiMatkul[i] > 4 )
  66.         {
  67.             printf("ERROR: Angka yang anda masukkan tidak valid!!\n");
  68.             break;
  69.         }
  70.        
  71.         mutuMatkul[i] = sks * nilaiMatkul[i];
  72.  
  73.         totalMutu += mutuMatkul[i];
  74.         totalSKS += sks;
  75.  
  76.         printf( "\n" );
  77.     }
  78.  
  79.     ips = totalMutu / totalSKS;
  80.  
  81.    
  82.     std::cout << "Nama\t: " << nama << "\n";
  83.     std::cout << "NIM\t: " << nim << "\n";
  84.     std::cout << "Jurusan\t: " << jurusan << "\n";
  85.     printf( "IPS\t: %.2f\n", ips );
  86.     makeLine(55);
  87. }
Add Comment
Please, Sign In to add comment