Question

C++ INSTRUCTIONS Problem Specification : Write a program that reads a group of numbers from the...

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

Homework Answers

Answer #1
#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;
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
(Write in C++) Write a program that reads in two numbers and, if the input is...
(Write in C++) Write a program that reads in two numbers and, if the input is valid, outputs 2 times the product of the integers that lie between the two values (including the values themselves). If either number is not an integer, or if the first number is not less than the second number, just output an error message. The sample runs below should give the idea. User inputs are in bold. Important Notes: Your program should use a loop...
Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store...
Write a c++ program that evaluates the first 50 numbers of the Fibonacci sequence and store the numbers in an array. The c++ program asks the user for an input to enter a positive integer 'n' and display the nth fibonacci number "FibN" that is stored inside of the array
Use C++ Write a program that first reads in how many whole numbers the user wants...
Use C++ Write a program that first reads in how many whole numbers the user wants to sum, then reads in that many whole numbers, and finally outputs the sum of all the numbers greater than zero, the sum of all the numbers less than zero (which will be a negative number or zero), and the sum of all the numbers, whether positive, negative, or zero. The user enters the numbers just once each and the user can enter them...
Write a program that reads in a table of numbers and finds out the average of...
Write a program that reads in a table of numbers and finds out the average of each row and column. This program should first take two numbers as number of rows and columns as input from the user.
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF...
WRITE C++ PROGRAM FOR 1,2,3,4 PARTS of question, DO ADD COOMENTS AND DISPLAY THE OUTPUT OF A RUNNING COMPILER QUESTION: 1) Fibonacci sequence is a sequence in which every number after the first two is the sum of the two preceding ones. Write a C++ program that takes a number n from user and populate an array with first n Fibonacci numbers. For example: For n=10 Fibonacci Numbers: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 2): Write...
C++ Create a program that will use pointers to determine the average (to 1 decimal place)...
C++ Create a program that will use pointers to determine the average (to 1 decimal place) of a series of grades entered into an array. You can assume a maximum of 15 students and the user will end input with a sentinel value. Make sure to use pointer increment and a pointer comparison while loop, and not array notation or array index numbers or offsets. You will use a function called getgrades. Send the array name (a pointer constant) to...
Please write a java program Instructions Your goal is to take N integer inputs from the...
Please write a java program Instructions Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
Write a program that takes n integer numbers from the user, and then counts the number...
Write a program that takes n integer numbers from the user, and then counts the number of even numbers and odd numbers and print them to the screen. Sample Output: Enter how many numbers you have: 10 Enter the 10 numbers: 1 3 19 50 4 10 75 20 68 100 The number of even numbers is: 6 The number of odd numbers is: 4 (( in java ))
Instructions Write a Java code Your goal is to take N integer inputs from the user...
Instructions Write a Java code Your goal is to take N integer inputs from the user -- N's value will be given by the user as well. You can assume the user provides a valid value for N, i.e., >0. Store the input integers in an array of size N in the order they are provided. These tasks should be done in the main() method. Create a new method called checkArray() that will take the previously created array as input...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT