Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int asize = 5;
- int nums[asize] = { 0 };
- //create accumulator for sum
- int sum = 0;
- double avg;
- //prompt the user to store values into the array
- for (int index = 0; index < asize; index++)
- {
- //sum = sum + nums[index];
- //cout << "sum is " << sum << endl;
- //prompt for a number
- cout << "Enter a number: ";
- //store in position [index] of array
- cin >> nums[index];
- //add this to your accumulator
- sum = sum + nums[index]; //or sum += nums[index];
- }
- //print the total
- cout << "sum is " << sum << endl;
- //calculate the average
- avg = (double)sum / asize;
- //print the average
- cout << "avg is " << avg << endl;
- //print the values greater than avg
- cout << "The values above average are" << endl;
- for (int index = 0; index < asize; index++)
- {
- //do I print this number?
- if (nums[index] > avg)
- {
- cout << nums[index] << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement