Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //James Waldman
- //4/20/18
- //Homework 4
- #include <iostream>
- using namespace std;
- void getData(int *, int);
- double getAvg(int *, int);
- double getTotal(int *, int);
- int main()
- {
- int *Movies = NULL;
- int SIZE;
- cout << "How many students were surveyed? " << endl;
- cin >> SIZE;
- while (SIZE < 0) {
- cout << "Error. Try again." << endl;
- cin >> SIZE;
- }
- Movies = new int[SIZE];
- getData(Movies, SIZE);
- cout << "The number of Movies seen: " << endl;
- cout << getTotal(Movies, SIZE) << endl;
- cout << "The average number of Movies seen: " << endl;
- cout << getAvg(Movies, SIZE) << endl;
- delete Movies;
- Movies = NULL;
- system("pause");
- return 0;
- }
- void getData(int *array, int size)
- {
- cout << "How many movies did they watch?" << endl;
- for (int i = 0; i < size; i++)
- {
- cout << "Student " << (i + 1) << ": ";
- cin >> *(array + i);
- while (*array + i < 0) {
- cout << "Error. Try again." << endl;
- cin >> *(array + i);
- }
- }
- }
- double getAvg(int *array, int size)
- {
- double total = 0;
- double avg;
- for (int i = 0; i < size; i++)
- {
- total += *(array + i);
- }
- avg = total / size;
- return avg;
- }
- double getTotal(int *array, int size)
- {
- double total = 0;
- double *total1 = NULL;
- for (int i = 0; i < size; i++)
- {
- total += *(array + i);
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement