Guys I need help. When I am already done inputting the needed information, when it comes to outputting file stream to a notepad it stops and says "program.exe has stopped working. windows is checking for a solution" and there is a loading bar. please help i don't know what I did wrong. The part with the red font is where my program is having problems with. here is my code guys:

#include<iostream>
#include<string>
#include<windows.h>
#include<fstream>
#include <iomanip>
#include<cctype>
#include<cstdlib>

using namespace std;

struct TF
{int units, punits, misc;};

struct studre
{
       string Sno;
       string Fname;
       string Mname;
       string Sname;
       string course;
       int year;
       int fees;
      
      
};

void ClearScreen();
void input();
int main()
{   
    int total;
    int i;
    studre level[100];
    int x;
    studre record[100];
    TF amount;
    amount.punits=800;
    amount.misc=2000;
    double tuition;
    ofstream output;

    while(true)
    {
    cout<<"Enter number of students that will enroll (Max. of 5 students only)"<<endl;
    cin>>x;

try
{
if(x<1||x>5)
{
throw x;
}

}
catch(int a)
{
ClearScreen();
cout<<"Invalid input. Please try again."<<endl;
continue;
}





for (int i=0;i<x;i++)

    {
        cin.ignore();
        cout<<endl;
        cout<<"Student Number:"<<"["<<i+1<<"]:"<<endl;
        getline(cin,record[i].Sno);
         
        cout<<"Enter First Name:"<<"["<<i+1<<"]:"<<endl;
        getline(cin,record[i].Fname);
        
        cout<<"Enter Middle Name:"<<"["<<i+1<<"]:"<<endl;
        getline(cin,record[i].Mname);
       
        cout<<"Enter Last Name:"<<"["<<i+1<<"]:"<<endl;
        getline(cin,record[i].Sname);
       
        cout<<"Enter Course:"<<"["<<i+1<<"]:"<<endl;
        getline(cin,record[i].course); 
       
        cout<<"Enter Year:"<<endl;
        cin>>level[i].year;
        {
        cout<<"Enter Units:"<<endl;
        cin>>amount.units;
        total=amount.units*x;
        }
        ClearScreen();
        }


output.open("record.txt", ios::app);

output<<"Student Number:"<<record[i].Sno<<endl;
output<<"First Name:"<<record[i].Fname<<endl;
output<<"Course:"<<record[i].course<<endl;

output.close();

system ("pause");
return 0;
    
}


}

void ClearScreen()
  {
  HANDLE hStdOut;
  CONSOLE_SCREEN_BUFFER_INFO csbi;
  DWORD count;
  DWORD cellCount;
  COORD homeCoords = { 0, 0 };
  hStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
  if (hStdOut == INVALID_HANDLE_VALUE) return;
  if (!GetConsoleScreenBufferInfo( hStdOut, &csbi ))
  return;
  cellCount = csbi.dwSize.X *csbi.dwSize.Y;
  if (!FillConsoleOutputCharacter(
    hStdOut,
    (TCHAR) ' ',
    cellCount,
    homeCoords,
    &count
    )) return;
  if (!FillConsoleOutputAttribute(
    hStdOut,
    csbi.wAttributes,
    cellCount,
    homeCoords,
    &count
    )) return;
  SetConsoleCursorPosition( hStdOut, homeCoords );
  }

I see that you have used file streams. I beg your pardon if i was wrong about it. But i don't know why you used them as the instructions didn't say about that.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.