{
char choice;
cout << " Enter w to write or r if you want to read from the file: ";
cin >> choice;
if(choice == 'W'| 'w')
{
int x;
cout << "How many numbers would you like to add? ";
cin >> x;
for(int i=0; i < x; i++)
{
double text;
cout << "Enter number to add: ";
cin >> text;
myfile << text << endl;
}
myfile.close();
return 0;
}
elseif (choice == 'R' | 'r')
{
string line;
ifstream myfile (filename.c_str());
if (myfile.is_open())
{
while ( myfile.good() )
{
getline (myfile,line);
cout << line << endl;
}
myfile.close();
}
return 0;
}
}
So when I compile and run my program I give the user the option to enter w or r to read or write from a text file. But no matter what letter I enter it always enters the loop that allows the user to write to the file. What am I doing wrong?