Hi
I'm writing a program that will ask the user for a filename and the number of Fibbonacci numbers they would like to see, assign that name to a file, output those numbers to that file then display the file. My problem is that the numbers aren't being written to the file and therefore nothing is displayed. Could someone please point me in the direction where my problem is? Thank you.
Code:#include <iostream> #include <fstream> using namespace std; //function prototypes void fibon(ofstream &fibFile, int num_of_fib); int main () { int num_fibonacci, validNum, validFile, display; char filename[30]; ofstream outFile; / do { validFile=0; cout << "\nEnter the name that you want the file to called" << " (up to thirty charaters):\n"; cin >> filename; outFile.open("c:\\filename.dat");//take some stuff out if (outFile.fail()) { cout << "\nThe file did not open. Please input another name.\n"; validFile = 1; } } while (validFile == 1); do { validNum=0; cout << "\nHow many Fibonacci Numbers do you want? (You can have" << " between 2 and 47 numbers)\n"; cin >> num_fibonacci; if((num_fibonacci < 2) || (num_fibonacci >47)) { cout << "\nYou must have at least 2 Fibonacci Numbers and " << "no more than 47 numbers"; validNum=1; } }while (validNum==1); void fibon(ofstream &outFile, int num_fibonacci); outFile >> display; cout << "Here are your "<< num_fibonacci <<" Fibonacci Numbers:\n"; << display << endl: outFile.close(); return 0; } ////////////////////////////////////////////////////fibon function void fibon(ofstream &fibFile, int num_of_fib) { int first = 0, second = 1, next; if (num_of_fib == 2) { fibFile << first << second; } else { fibFile << endl << first << " "<< second; num_of_fib = num_of_fib -2; while(num_of_fib > 0) { next = first + second; fibFile <<" "<< next; second = first; next = second; num_of_fib--; } } }