I need help on this program.....it needs to be basic programming nothing fancy a
ID: 3537747 • Letter: I
Question
I need help on this program.....it needs to be basic programming nothing fancy and must read to an outfile.....if you have any questions please ask.....thanks!!
Write a program to read in X integer values. X is unknown. Find the number of values read in, the sum of the values and the average(to one decimal place). Label ALL output , use a nice format, and MUST read results to an outfile.
Data for numbers:
Data Set 1: 10 15 23 0
Data Set 2: 1111 5732 6162 3123 0
Data Set 3: -5 -42 -100 -5 -10 0
Data Set 4: 7 0
Data Set 5: 0
Run your program five times, one for each data set. You will have one program that handles and list numbers. You will have five outputs for this program. Inserting a loop would be helpful.
Explanation / Answer
#include<iostream>
#include<fstream>
#include <iomanip>
using namespace std;
int main()
{
ofstream outfile(".txt");
int count =0;
int sum = 0;
int input;
cout << " Enter input integer (0 to end)";
while(input!=0)
{
sum = sum + input;
count++;
}
double average = static_cast<double> (sum)/static_cast<double> (count);
outfile << " sum of numbers given by " << sum << endl;
outfile << " average of numbers given by " << average << endl;
outfile.close();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.