C++ visual basic. using a loop to read data from a file, calculating average, sum ( total), amount of numbers?
-
he Student CD contains a file named random. txt. This fi le contains a long list of random numbers. Copy the file to your hard dri ve and then write a program that opens the file, reads all the numbers from the fi le, and calculates the fo llowing: A) The number of numbers in the fi le B) The sum of all the numbers in the file (a running total) C) The average of all the numbers in the file The program should display the number of numbers found in the file, the sum of the numbers, and the average of the numbers. Each output for the project should be accompanied with a statement such as: “The average of the data items is ____”. *this is what i have come up with so far. No arrays are being used. just loops, reading data from a file, and calculating. im stuck and i dont no where to go from here. please assist or give examples... #include <iostream> #include <fstream> using namespace std; int main() { ifstream inputFile; //File stream object int sum=0; int number; //to hold a value from the file int count=1; //loop counter, intialized with one inputFile.open("random.txt"); if(!inputFile>>number) cout<<"Error opening the file.\n"; else { while(inputFile >> number) { cout<<number<<endl; } inputFile.close(); } return 0; }
-
Answer:
Here is a sample program which demonstrates this exact problem: http://programmingnotes.freeweq.com/?p=670
e at Yahoo! Answers Visit the source
Related Q & A:
- How to write binary data to a file?Best solution by Stack Overflow
- In Visual Studio 2012 or 2013, how can I register a DLL file on Windows 7 64-bit computer using a Custom Action command?Best solution by Stack Overflow
- Do I need a special ISP package to do a file hosting site?Best solution by Yahoo! Answers
- Codes for a simple visual basic program.Best solution by vbtutor.net
- Is java or visual basic a machine level, low level, high level or binary level programming language?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.