hi im new to the forums and im stuck on a part of my code that i need to do for homework
in the code below in my loadPuzzle function it seems to skip my cin.getline and i dont know why.
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
enum menu {load=1,solve,create,quit};
int menu();
void loadPuzzle(ifstream&);
void printUnsolvedPuzzle(ifstream&);
int main()
{
ifstream file;
bool exit = false;
while (exit != true)
{
switch (menu())
{
case load:
loadPuzzle(file);
printUnsolvedPuzzle(file); //ignore this part for now
break;
case solve:
cout << "Empty" << endl;
cout << endl;
break;
case create:
cout << "Empty" << endl;
cout << endl;
break;
case quit:
cout << "Quiting program" << endl;
exit = true;
break;
default:
cout << "Error. Invalid input." << endl;
}
}
return 0;
}
int menu()
{
int choice;
cout << "***********************\n"
"* *\n"
"* Find a Word *\n"
"* *\n"
"***********************" << endl;
cout << "1. Load Puzzle \n"
"2. Solve Puzzle \n"
"3. Create Puzzle \n"
"4. Quit Program \n"
"Choice: ";
cin >> choice;
cout << endl;
return choice;
}
void loadPuzzle (ifstream& file)
{
char fileName[30];
cout << "Enter a file name: ";
file.getline(fileName,'\n');
file.open(fileName);
}
void printUnsolvedPuzzle(ifstream& file) //ignore this part
{
char myString[80];
while(!file.eof())
{
file.getline(myString,sizeof(myString));
cout << myString << endl;
}
file.close();
}
i have a feeling its to do with my switch statement