I'm trying to get a string and a number to write to a file number of times, which the user determines. But the loop only partially runs before closing.
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
int main()
{
string companyName;
int numberOfPeople, chargePerPerson;
int timesToRun, count;
ofstream Seminar("Seminar.dat");
cin >> timesToRun;
for(count = 0; count < timesToRun;count++)
{
cout << "Enter the company name: ";
getline(cin, companyName);
cin.get();
cout << "\nEnter the number of people attending: ";
cin >> numberOfPeople;
cin.get();
Seminar << companyName << "~" << numberOfPeople << endl;
}
Seminar.close();
system("PAUSE");
return 0;
}
3
Enter the company name: blahblah blah
Enter the number of people attending: Enter the company name:
Enter the number of people attending: Enter the company name:
Enter the number of people attending: Press any key to continue . . .