Output a text file into Excel

I need to know how to output the user's input into a textfile so I can open it up on Excel. Thanks! Here's my work so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//Running Mean for N points with even weights

#include <iostream>
#include <iomanip>
#include <vector>
#include <numeric>
#include <functional>
#include <fstream>
using namespace std;
//Function type    name           (parameter1, parameter2,....)      
           double calculateAverage(int numberofterms, int number_of_elements_avg, vector<double> temperature);
int main ()
{
int numberofterms;  //Declare variables
int number_of_elements_avg; 
double tempstorage, average;
vector<double> temperature; //Define a empty vector of doubles.
vector<double> movingavg(100,0);    //100 doubles with the value 0 (?)
int i = 0; //Loop counter

cout<<"Enter the number of terms you want: " <<endl;
cin>>numberofterms;
cout<<"Enter how many pt average you would like to take: "<<endl;
cin>>number_of_elements_avg;


for (i==0; i<numberofterms; i++)
{ 
double average;

cout<<"Enter temperature you want to input in Celsius "<<(i+1);
cout<<": ";
cin>>tempstorage;
temperature.push_back(tempstorage);
}

average = calculateAverage(numberofterms, number_of_elements_avg, temperature); //?

system ("PAUSE");
return 0;
}

double calculateAverage(int numberofterms, int number_of_elements_avg, vector<double> temperature){
	int mau = 2, h = 0, mau_large = 0;   //?
	double average = 0, sumElement = 0;  //?
	
	//for (Is integer 1 to the remainder of i will be 0 or 1?or the number of terms divided by 2 to number of terms divided by 2 
	//+1 
	for(int i = 1; i <= (numberofterms%2==0?numberofterms/2:numberofterms/2+1); i++){
		if(mau <= number_of_elements_avg){     //if mau=2 is less than or equal to to the number of elements average
			for(int j = 1 ; j <= mau; j++)     //for integer j = 1 and j less equal mau 
				sumElement += temperature[j-1]; //Add the value of temperature[j-1] to the sumelement variable (Replaced)
			average = sumElement / mau;         //average is the sum of the element divided by mau.
			cout<< "Temp_running mean " << i << " is "  << average <<endl;    
			mau++;   //increasing mau (?)
			sumElement = 0;  //(?)
		}else{
			h = mau - number_of_elements_avg;   //else h = mau=2 - number of elements_avg
			mau = number_of_elements_avg;       //mau = number_of_elements_avg
			for(int j = 1 + h ; j <= h + mau; j++)  //for(int j = 1+h; j<= h+2, j++)
				sumElement += temperature[j-1];    //Add the value of temperature[j-1] to the sumelement variable 
			average = sumElement / mau;             //average is the sum of the element divided by mau.
			cout<< "Temp_running mean " << i << " is "  << average <<endl;
			mau++;   //increasing mau (?)
			sumElement = 0; //(?)
		}
	}
	//mau_large = 2 +(numberof terms-(numberofterms remainder 0 or 1=0 or numberofterms/2 to numberofterms/2+1))-1;
	mau_large = 2 + (numberofterms - (numberofterms%2==0?numberofterms/2:numberofterms/2+1)) - 1;
	//for (int i = 1+(numberofterms remainder 0 or 1 ==0  or numberofterms/2:numberofterms/2+1); i <= numberofterms; increasing in between.
	for(int i = 1+ (numberofterms%2==0?numberofterms/2:numberofterms/2+1); i <= numberofterms; i ++){
	//if(mau_large > numberofelementsavg
		if(mau_large > number_of_elements_avg)
	//mau = numberofelementsavg
			mau = number_of_elements_avg;
	//else mau = mau_large
		else mau = mau_large;
	//if (h>O) 
		if(h > 0){
			//h increases
			h++; //(?)
	//for (int j = 1+h and j less than or equal to h + mau; j++)
			for(int j = 1 + h; j <= h+mau; j++){

				sumElement += temperature[j-1]; //Add the value of temperature[j-1] to the sumelement variable
			}
			average = sumElement / mau;  //average is the sumElement/mau
			cout<< "Temp_running mean " << i << " is "  << average <<endl;  
			mau_large --;  //mau_large decreasing iteratively 
			sumElement = 0; 
		}else{                  //else
			int t = (numberofterms - (numberofterms%2==0?numberofterms/2:numberofterms/2+1)); //int t = (numberofterms-(numberofterms remainder 0 or 1 = 0 or 
			//number of terms/2 to numberofterms/2+1))

			int k = numberofterms - i;  //int k = numberofterms-i
			if(t <=2)   //if t <= 2
				h = numberofterms - mau + 1; //h = numberofterms-mau+1
			else                             //else
				h= numberofterms - mau;      //h=numberofterms-mau
			if(k<2)                          //if(k<2)
				h= numberofterms - mau + 1;  //h = numberofterms-mau+1
			for (int j = h  ; j < h + mau ; j++){  //for int j=h or j<h+mau; increasing increments
				sumElement += temperature[j-1];   //Add the value of temperature[j-1] to the sumelement variable  
			}
			average = sumElement / mau;    //average = sumElement/mau
			cout<< "Temp_running mean " << i << " is "  << average <<endl;
			mau_large --;     //decreasing mau in incriments
			sumElement = 0;   
			h = 0;
		}
	}
	return average;

 ofstream myfile;
  myfile.open ("Temperature.txt");
  myfile <<average;
  myfile.close();


The program was free from errors but no text file was created.

You might want to look into csv files. They are easy to make, and are compatible with the mainstream database and spreadsheet programs.
Also, as near as I can tell, return average and your file output are outside of a function and never execute. The file output should probably have it's own function, or be integrated into an existing one.
Topic archived. No new replies allowed.