Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void input();
- int main(void)
- {
- // Initialize variables
- int number;
- int counter;
- int average;
- int sum;
- // Initialize pointers
- int *averagePtr;
- int *sumPtr;
- int *numberPtr;
- int *counterPtr;
- // Assign pointer addresses
- averagePtr = (&average);
- sumPtr = (&sum);
- numberPtr = (&number);
- counterPtr = (&counter);
- cout << "Enter in a positive number, a negative will stop it" << endl;
- do
- {
- cin >> (*numberPtr);
- if((*numberPtr) >= 0)
- {
- (*sumPtr) = (*sumPtr)+(*numberPtr);
- (*counterPtr)++;
- }
- }
- while((*numberPtr) >= 0);
- (*averagePtr) = (*sumPtr)/(*counterPtr);
- cout << "The Average is " << (*averagePtr) << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment