Hello. I am working on a solution that I cannot get an if() condition to work. The condition is true but it skips it as though it were false. Specifically this code
// Return to function getRecipeName if listView is true
if (listView = true)
{
string getRecipeName(string prompt);
} // Else continue
Can someone help please? My function code is below.
string getDisplayRecipe(string validRecipe)
{
// Clear the screen
system("CLS");
// Name the inFile and outfile
ifstream inFile;
ofstream outFile;
// Open recipe file
inFile.open(validRecipe);
// Initiate variable "character"
char character;
// Get the first character from the recipe
inFile.get(character);
// Loop until the end of the file
while (!inFile.eof())
{
//Display the character
cout << character;
// Get the next character from the recipe
inFile.get(character);
} // End while loop
// Close both inFile & outFile
inFile.close();
outFile.close();
// Check if user entered 'list'
bool listView = (validRecipe == "list.tsp");
cout << boolalpha;
// Return to function getRecipeName if listView is true
if (listView = true)
{
string getRecipeName(string prompt);
} // Else continue
// Return validRecipe variable
return validRecipe;
}
What @lastchance said is correct, but the assignment of true would always evaluate to true in the if condition. So there's another problem here.
The 2nd problem is that the statement string getRecipeName(string prompt); is actually declaring a function, not calling one. I believe you instead want something like: