I've been trying to get one of my program to work properly for a while now but it wont, to be honest I think the problem could be with my compiler (GCC 3.2.2) because this should work.
The problem doesn't occur until the first while loop runs throught once, then if I answer y to the prompt asking me if I want to add another distribution the program skips getline(cin,date);
Compiler information:
gcc version 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)
Code:
#include <iostream>
#include <fstream>
#include <string>
int main() {
using namespace std;
// initialise variables
char responce = 'y'; // starts as yes so the loop will run at least once
string date;
string distribution;
string version;
while(toupper(responce) != 'N') {
system("clear"); // clear screen
cout << endl << "New list entry" << endl;
// get information
cout << "Date of release: ";
getline(cin,date);
cout << "Name of distribution: ";
getline(cin,distribution);
cout << "Version number: ";
getline(cin,version);
// write information
ofstream a_file("CS-FSLUG_dlist",ios::app);
a_file << date << ": " << distribution << " " << version << endl;
a_file.close();
// prompt for continuation
responce = 'p';
while (toupper(responce) != 'Y' && toupper(responce) != 'N') {
cout << "Enter another distribution (y/n): ";
cin >> responce;
}
system("clear"); // clear screen
}
return 0;
}