C++
INSTRUCTIONS Problem Specification
: Write a program that reads a group of numbers from the user and places them in an array of type float. Once the numbers are stored in the array, the program should average and print the result. Use pointer notation wherever possible.
Program Output (with Input Shown in Bold):
Enter number: 2 Enter another (y/n)? y
Enter number: 4 Enter another (y/n)? y
Enter number: 6 Enter another (y/n)? y
Enter number: 8 Enter another (y/n)? y
Enter number: 10 Enter another (y/n)? n
Average is 6
#include <iostream> using namespace std; int main() { float arr[1000]; int size = 0; char choice = 'y'; while (choice == 'y' || choice == 'Y') { cout << "Enter number: "; cin >> *(arr+size); size++; cout << "Enter another (y/n)? "; cin >> choice; } float total = 0; for (int i = 0; i < size; ++i) { total += *(arr+i); } cout << "Average is " << total/size << endl; return 0; }
Get Answers For Free
Most questions answered within 1 hours.