Question #20197

I need help analyzing Netflix data, using global variables. I need to store the number of ratings and the sum of ratings in arrays. I need to write a function that that will give the average ratings for the movies.

Expert's answer

#include <conio.h>

#include <iostream>

using namespace std;

int numberofratings[100];

int number=0;

double averageratings (){

double sum=0;

for(int i=0;i<number;i++){

sum+=numberofratings[i];

}

return sum/number;

}

int main()

{

cout<<"Enter number of ratings: ";

cin>>number;

for(int i=0;i<number;i++){

cout<<"Enter value of rating "<<(i+1)<<":

";

cin>>numberofratings[i];

}

cout<<"Average ratings= "<<averageratings();

getch();

return 0;

}

## Comments

## Leave a comment