I created a function in my program that would take info about a teacher and their class room and then write it to a file. Then I added a loop so that people could keep adding more teachers. Then I thought I would be good to make a break statement so people can easily close the program. The problem is, is that after you cycle through this once it starts looping and never stops for user input. Here's the code-
Code:
#include <iostream>
#include <fstream>
using namespace std;
int teacher_info(char name[10], char subject[10], int room_num)
{
ofstream fout("school.txt");
fout << name << ":\n\tSubject: " << subject << "\n\tRoom number: " << room_num << endl;
fout.close();
return 0;
}
int main()
{
char name[10], subject[10];
int room_num;
cout << "\nNOTE: to exit type 'exit' as the teacher name." << endl;
while (true)
{
cout << "\nName: ";
cin >> name;
if (name == "exit")
break;
cout << "\nSubject: ";
cin >> subject;
cout << "\nRoom number: ";
cin >> room_num;
teacher_info(name, subject, room_num);
}
return 0;
}