D-Gj

Ocenki

Apr 17th, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. string uspeh ( double );
  7.  
  8. int main ( )
  9. {
  10.     int ocenki[50], broj_na_predmeti, zbir = 0;
  11.     cout << "Kolku predmeti izuchuva uchenikot? ";
  12.     cin >> broj_na_predmeti;
  13.  
  14.     if ( !cin || broj_na_predmeti < 1 || broj_na_predmeti > 50 )
  15.     {
  16.         cout << "Losh vnes!" << endl;
  17.         return 1;
  18.     }
  19.  
  20.     for (int i = 0; i < broj_na_predmeti; ++i)
  21.     {
  22.         cout << "Vnesete ocenka: ";
  23.         cin >> ocenki[i];
  24.  
  25.         if ( ocenki[i] < 1 || ocenki[i] > 5 )
  26.         {
  27.             cout << "Ocenkata ne mozhe da bide pomala od 1 ili pogolema od 5!" << endl;
  28.             --i;
  29.             continue;
  30.         }
  31.  
  32.         cout << uspeh ( ocenki[i] ) << "." << endl;
  33.         zbir += ocenki[i];
  34.     }
  35.  
  36.     double prosek = (double)zbir / (double)broj_na_predmeti;
  37.  
  38.     cout << endl << "Prosekot na uchenikot e: " << prosek << " (" << uspeh ( prosek ) << ")." << endl;
  39.     return 0;
  40. }
  41.  
  42. string uspeh ( double ocenka )
  43. {
  44.          if ( ocenka >= 1.  && ocenka < 1.5 ) return "Nedovolen";
  45.     else if ( ocenka >= 1.5 && ocenka < 2.5 ) return "Dovolen";
  46.     else if ( ocenka >= 2.5 && ocenka < 3.5 ) return "Dobar";
  47.     else if ( ocenka >= 3.5 && ocenka < 4.5 ) return "Mnogu dobar";
  48.     else if ( ocenka >= 4.5 && ocenka <= 5. ) return "Odlichen";
  49.  
  50.     return "";
  51. }
Advertisement
Add Comment
Please, Sign In to add comment