Cout Issue


#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;

int main()
{
int counter;
string line;
string word;
bool palindromes=true;

ifstream inputFile("File");
if(!inputFile)
{
return 0;
}

while(inputFile)
{
inputFile >> line;
for(counter=0;counter<line.length()/2;counter++)
{
if(line[counter]!=line[line.length()-counter-1])
{
palindromes=false;
}
}
if(palindromes==true)
{
if (line.length() > 7)
{
cout << palindromes << endl;
}
}
palindromes=true;
}
return 0;
}

I wrote this code, but the only thing coming out is "1" 3 times. It should print out 3 palindromes instead.
I think the problem is that you're couting palindromes, which is a boolean. In a console application, this will be output as 1 for true and 0 for false. since your cout<<palindromes is in a if(palindromes) conditional, it is always giving you ones.

I think what you want is cout << line[counter].

I hope this helps, I believe I understood what your program is supposed to do.
Topic archived. No new replies allowed.