Question

I have an assignment in C# due and I am unsure of where to even begin....

I have an assignment in C# due and I am unsure of where to even begin.

Assignment: Write a C# console app that will input a text file of numbers. For these numbers, find the number of numbers (one per line), the largest of these numbers, the smallest of these number, and the average of these numbers. I'm attaching two files, a short file with the numbers 1 thru 9 for testing and another larger file for the actual processing outlined above.

What to turn in:
1. The .cs file, with comments, program description, name, etc.
2. Another file you can create yourself containing the number of numbers, largest, smallest, average of the numbers, etc. Comment on what the average of these numbers is (I don't know, but I have an idea).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

// C# code

//Please change the file path according to your input file path

//This program works for any numbers in file no matter how many....

using System;
using System.IO;

class Program
{
static void Main(string[] args)
{
//Open file to read
StreamReader read = new StreamReader(@"C:\Users\naren\source\repos\input file get average\input file get average\input.txt");
// variables
int sum = 0, counter =0,max =0,min=0;
double avg = 0;
//While data is being read
while(!read.EndOfStream)
{
//Parse line to int to store in int variable
int num = int.Parse(read.ReadLine());
//update counter
counter++;
//If counter run first time
// initialize min and max
if(counter==1)
{
min = num;
max = num;
}
//find min and max
else
{
if (min > num)
min = num;
if (max < num)
max = num;
}
//Find summation of numbers
sum += num;
  
}
//Find average
avg = sum / counter;
//Print
Console.WriteLine("The max = {0}\nThe Min = {1}\nThe Average = {2:N}\n", max, min, avg);
//pause
Console.ReadLine();
}
}

//input.txt

//Output

//If you need any help regarding this solution ........ please leave a comment..... thanks

Add a comment
Know the answer?
Add Answer to:
I have an assignment in C# due and I am unsure of where to even begin....
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • PLEASE HELP C++ some of the content in random.txt Program #2 This problem is a modification...

    PLEASE HELP C++ some of the content in random.txt Program #2 This problem is a modification of Problem 24 on page 302 of the Gaddis text with two small additions. (A scan of this problem can be found on the last page of the assignment.) In this assignment, your program will read in a list of random numbers from an input file, random. txt (found on eLearning in the "Homework Input Files" folder), and calculate the following statistics on those...

  • please read directions first. this is supposed to be a hybrid programe add comments please JAVA...

    please read directions first. this is supposed to be a hybrid programe add comments please JAVA please add comments Programming Project 1 and Programming Project 2 "Hybrid" Your goal is to write a program that combines the functionality of both Programming Project 1andProgramming Project 2 into a single program. That is, your program should read a file ( Numbers.txt) of numbers of type double that contains some duplicates and is ordered smallest to largest. Your program should ignore the duplicate...

  • CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment will be dropped....

    CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment will be dropped. Important: This is an individual assignment. Please do not collaborate. It must be submitted on-line (Blackboard). No late assignment will be accepted Minimal Submitted Files You are required to turn in the following source file: assignment11.s Objectives: -write assembly language programs to:             -perform arithmetic on floating point numbers             -use syscall operations to display floating point numbers and strings on the console window...

  • I am confused on how to read valid lines from the input file. I am also...

    I am confused on how to read valid lines from the input file. I am also confused on how to count the averages from these valid input lines to keep running the total from these valid lines. If you could show an example of an input and output file that would be amazing as well. Purpose        Learn how to use Java input/output. Due Date       Per the Course at a Glance. Can be resubmitted. Submissions           In this order: printed copy of...

  • The program will need to accept two input arguments: the path of the input file and...

    The program will need to accept two input arguments: the path of the input file and the path of the output file. See etc/cpp/example.ifstream.cpp for the basis of how to do this. Once the input and output file paths have been received, the program will need to open the input and output files, read and process each input file line and create a corresponding output file line, close the input and output files, and then create and output some summary...

  • I'm trying to do this in a C# Console App.(NET Framework).I've attached the Code that will...

    I'm trying to do this in a C# Console App.(NET Framework).I've attached the Code that will be required to complete. Any Guidance will be appreciated. C# Console File I/O Project Assignment Working with files and being able to process data in and out of a file is critical to the programmer’s role. Almost every organization will have to deal with files one way or another. For example, it is very common for accountants to use spreadsheets for calculations and sometimes...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global...

    Language is C++ NOTE: No arrays should be used to solve problems and No non-constants global variables should be used. PART B: (Statistics Program) – (50%) Please read this lab exercise thoroughly, before attempting to write the program. Write a program that reads the pairs of group number and student count from the text file (user must enter name of file) and: Displays the number of groups in the file (5 %) Displays the number of even and odd student...

  • I need help in C++ assignment. please add statements and i am Xcode complier user. Requested...

    I need help in C++ assignment. please add statements and i am Xcode complier user. Requested files: CountDecades.cpp (Download) Maximum upload file size: 96 KiB Write a C++ program named CountDecades.cpp. In this program you will have two integer arrays. One named inputArray of size 20 containing the values: 83, 2, 23, 11, 97, 23, 41, 67, 16, 25, 1 , 4, 75, 92, 52, 6, 44, 81, 8, 64 in the order specified, and an empty integer array of...

  • CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment wil...

    CSE/EEE230 Assignment11 Due Date Thursday, April 25th, 5pm Note: the lowest scored assignment will be dropped. Important: This is an individual assignment. Please do not collaborate. It must be submitted on-line (Blackboard). No late assignment will be accepted Minimal Submitted Files You are required to turn in the following source file: assignment11.s Objectives: -write assembly language programs to:             -perform arithmetic on floating point numbers             -use syscall operations to display floating point numbers and strings on the console window             -use syscall...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT