levimoosky

Untitled

Nov 24th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdlib.h>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9.     int N;
  10.     string sz;
  11.     bool hiba, hiba1;
  12.  
  13.     do
  14.     {
  15.         cout << "A vizsgazok szama= ";
  16.         cin >> sz;
  17.  
  18.         N=atoi(sz.c_str());
  19.  
  20.         hiba=(N==0)&&(sz!="0");
  21.         if(hiba)
  22.         {
  23.             cout << "Nem jo jelsorozatot adott." << endl;
  24.         }
  25.  
  26.         hiba1=(N<=0);
  27.         if(hiba1)
  28.         {
  29.             cout << "Nem pozitiv egeszet adott." << endl;
  30.         }
  31.     }
  32.     while(hiba||hiba1);
  33.  
  34.     int psz[N];
  35.     for (int i=0; i<N; ++i)
  36.     {
  37.         do
  38.         {
  39.             cout << i+1 << ". vizsgazo pontszama= ";
  40.             cin >> sz;
  41.             psz[i]=atoi(sz.c_str());
  42.  
  43.             hiba=(psz[i]==0)&&(sz!="0");
  44.             if(hiba)
  45.             {
  46.                 cout << "Nem jo jelsorozatot adott." << endl;
  47.             }
  48.  
  49.             hiba1=(psz[i]<0)||(psz[i]>100);
  50.             if(hiba1)
  51.             {
  52.                 cout << "Nem 0 es 100 kozotti a pontszam." << endl;
  53.             }
  54.         }
  55.         while(hiba||hiba1);
  56.     }
  57.  
  58.     float atl=0;
  59.     for (int i=0; i<N; ++i)
  60.     {
  61.         atl=atl+psz[i];
  62.     }
  63.  
  64.     atl=atl/N;
  65.     cout << "Atlag= " << atl << endl;
  66.  
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment