VB icon

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: 1414
author picture
 
     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?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// 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 <iostream>
#include <fstream>
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");
}


Other 56 submission(s) by this author

 


Report Bad Submission
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:

Your Vote

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 ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.