Declaring an output txt in header?

My professor today told me I had to put my code to open a .txt file for output to go into above main(). She said the reason for this was because she hasn't taught us how to add specific code so I can send some stuff that are within my function to the .txt file. How am I supposed to do that? Ive been stuck for a few hours.


HERES MY CODE

//assignment 3
#include <iostream>
#include <fstream>
using namespace std;
void introduction();
int howmanynegative(int a,int b,int c);
int findsumandprod(int x, int y);
int main()
{

//here is where my declaration starts
fstream myfile;
myfile.open("numbersOutput.txt");


int first, second, third, neg, num_of_sets=0;

introduction();

cin>>first;
while(first!=999){ //To end loop please enter .99 for first number
cin>>second;
cin>>third;

myfile<<"The three original integers are "<<first<<" "
<<second<<" "<<third<<"."<<endl;

neg=howmanynegative(first, second, third);
myfile<<neg<<" of these numbers are negative."<<endl;

findsumandprod(first,second);
findsumandprod(second,third);
findsumandprod(third,first);

num_of_sets++;
cin>>first;

}

myfile<<num_of_sets<<" sets have been processed";
myfile.close();

system("pause");
return 0;
}





void introduction(){
cout<<"This program will take sets of numbers(in 3's) and call 2 "
<<"functions, one which will print our how many numbers are negative,"
<<"and one that will find the sum and product of the 3 numbers. "
<<"After it will count how many sets have been processed."<<endl<<endl;
}

int howmanynegative(int a,int b,int c){

int negative;

if(a<0&&b<0&&c<0){
negative=3;
return negative;
}
else if(a<0&&b<0||a<0&&c<0||b<0&&c<0){
negative=2;
return negative;
}
else if(a<0||b<0||c<0){
negative=1;
return negative;
}
else if(a>=0&&b>=0&&c>=0){
negative=0;
return negative;
}

}

int findsumandprod(int x, int y){

int sum, prod;

sum=x+y;
prod=x*y;
myfile<<x<<" and "<<y<<":"<<" Sum="<<sum<<" "<<"Product="<<prod<<endl;
myfile<<endl;

}
What she means is that you have to declare "fstream myfile" in the global memory space. Literally put the cursor at the end of Line 6, press enter and cut then paste your declaration to that point.
thanks you!
Topic archived. No new replies allowed.