# Sum and Average of a Number Using Text File in C++

Email
 Submitted on: 9/13/2015 6:54:12 AM By: Jake R. Pomperada Level: Beginner User Rating: Unrated Compatibility: C++ (general) Views: 3111

In this article I would like to share with you a sample program on how to store values in a text file using C++ this activity I wrote during my work as a college instructor in my programming class in C++. I called this program Sum and Average of a Number Using Text file in C++. All my programming activities that I wrote I am using Dev C++ or CodeBlock as my text editor. I hope you will find my work useful. If you have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.

code:
Can't Copy and Paste this?
 ``` //************************************** // Name: Sum and Average of a Number Using Text File in C++ // Description:In this article I would like to share with you a sample program on how to store values in a text file using C++ this activity I wrote during my work as a college instructor in my programming class in C++. I called this program Sum and Average of a Number Using Text file in C++. All my programming activities that I wrote I am using Dev C++ or CodeBlock as my text editor. I hope you will find my work useful. If you have some questions please send me an email at jake.r.pomperada@gmail.comand jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360. // By: Jake R. Pomperada //************************************** #include #include using namespace std; main() { int val[5], sum=0, average=0,list=0; ofstream file("result.txt"); cout << "\t\tSUM AND AVERAGE OF THE NUMBER 1.0"; cout << "\n\n"; for ( list=0; list < 5; list++) { cout << "Enter Item No. " << list+1 << " : "; cin >> list[val]; } cout << "\n"; cout << "\n List of Values"; cout << "\n\n"; for ( list=0; list < 5; list++) { sum+=list[val]; average = (sum/5); cout << " " << list[val] << " "; } cout << "\n\n"; cout << "\nThe total sum of the values is " << sum << "."; cout << "\nThe average of the values is " << average << "."; file << "\n\t ======== LIST OF VALUES ========"; file << "\n\n"; for ( list=0; list < 5; list++) { file << " " << list[val] << " "; } file << "\n"; file << "\nThe total sum of the values is " << sum << "."; file << "\nThe average of the values is " << average << "."; file.close(); cout << "\n\n"; system("PAUSE"); } ```

Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)