c1

četvrtak, 13. prosinca 2012.

Program with integer, modul, average


/* 

 Make a program in which user enters a number n...If n is not integer, print a message about that and ask a user to enter a number again...User than enters n numbers, after that program  prints an  average of entered numbers....


#include <iostream>
using namespace std;
int main()
{
    bool ok=false;
    int m;
    while(ok==false){
                      cout<<"Type number n:  "<<endl;
    double n;
    cin>>n;
    n=n*10;
    
    m=(int)n;
    if(m%10==0){
                m=m/10;
    cout<<endl<<"It's OK, you can continue....  "<<endl<<endl;
    ok=true;
}
else{
     cout<<endl<<"You need to enter integer....  "<<endl<<endl;
     ok=false;
     }
}
cout<<endl<<"Now type "<<m<<" numbers  "<<endl;
int niz[m];
int sum=0;
for(int i=0;i<m;i++){
        cin>>niz[i];
        cout<<endl;
        sum=sum+niz[i];
         }
float as;
float sum1=sum;
float m1=m;
as=sum1/m1;

cout<<"Average is:   "<<as<<endl;    

    system("PAUSE");
    return EXIT_SUCCESS;
}


Nema komentara:

Objavi komentar