Question: Assignment description: Write a C++ program that opens the file infile.txt and reads the numbers in the file. The user should see a menu with

Assignment description: Write a C++  Assignment description: Write a C++ program that opens the file infile.txtprogram that opens the file infile.txt and reads the numbers in the file. The user should see a menu with choices to see the total, the average, the count, or the option to quit. Accept only choices 1-4 for the menu input using a do-while loop. Use a switch statement to calculate and display the sum, average, or count, or "We are done."

Sample output:

This program uses the numbers in the infile.txt file.

What would you like to know?.

1. Sum of the numbers

2. Average of the numbers

3. How many numbers there are

4. Quit

Your choice: 1

Total sum is :623988

Press any key to continue . . .

This program uses the numbers in the infile.txt file.

What would you like to know?.

1. Sum of the numbers

2. Average of the numbers

3. How many numbers there are

4. Quit

Your choice: 2

Average of the numbers is: 4991.9

Press any key to continue . . .

This program uses the numbers in the infile.txt file.

What would you like to know?.

1. Sum of the numbers

2. Average of the numbers

3. How many numbers there are

4. Quit

Your choice: 3

Count of the numbers is: 125

Press any key to continue . . .

This program uses the numbers in the infile.txt file.

What would you like to know?.

1. Sum of the numbers

2. Average of the numbers

3. How many numbers there are

4. Quit

Your choice: 4

We are done.

Press any key to continue . . .

Grading:

( 4 pts): proper indentation

( 4 pts): opens infile.txt as hard-coded file name

( 4 pts): does not forget to close the file

( 6 pts): uses switch statement to follow the menu choice

( 4 pts): calculates total correctly

( 4 pts): calculates average correctly

( 4 pts): calculates count correctly

( pts):

So far this is what I have! But I keep getting the bottom two errors! What am I doing wrong?

#include #include #include using namespace std;

// Function to take user input and return the user choice int showMenu() {

int input = 0;

// Show the menu cout

cin >> input;

// return the input return input; }

// Function to do sum of array int sum(int arr[], int num) {

int s = 0;

for (int i = 0; i

return s; }

// Function to do average of array double avg(int arr[], int num) {

int s = sum(arr, num);

double average = (double)s / num;

return average; }

int main() {

string filename = "infile.txt"; ifstream in;

int NUMBERS[4096]; int num = 0;

cout

// opening file for Reading in.open(filename);

if (in.fail()) { cout Homework 2 Question 2- Microsoft Visual Studio Quick Launch (Ctrl+Q) File Edit View ProjectBuild Debug Team Tools Test Analyze Window Help Autumn Montgomery Local Windows Debugger. | -: source.cpp Homework 2 Question 2 (Global Scope) 49 50 51 52 53 54 string filename = "infile.txt "; ifstream in; int NUMBERS[4096]; int num = 0; cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!