#include <iostream>
#include <string>
using namespace std ;
int main()
{
string bored ;
do
{
cout << " program" <<endl ;
do
{
cout << "are you bored now (yes or no)" << endl ;
cin >> bored;
cout << bored << endl ;
}while (bored != "yes" || "no");
}while (bored != "yes");
cout << "you must be bored of my program now!" ;
return 0 ;
}
I made this as a simple do/while program, and if i run it, the second do/while statement will keep on going forever, without the [cin >> bored;] line working?
When posting code, please use code tags. Doing so preserves indentation (if there ever was any) and highlights keywords.
An immediate problem that pops up is this:
}while (bored != "yes" || "no");
You cannot "chain" elements like that in a condition.
You can only chain conditions. So above "no" becomes a condition on its own (and it's always true).
So the correct test would probably be...
}while (bored != "yes" && bored != "no");
"While bored isn't yes AND bored isn't no either..."
However I'm not sure if this is really what you want to accomplish.
Please use code tags when posting code, to make it readable.
Look at the following line:
}while (bored != "yes" || "no");
That's not doing what you probably meant it to do. The expression:
"no"
always evaluates to true, as it is non-zero. This means that the expression:
(bored != "yes" || "no");
always evaluates to true.
You probably meant to do:
}while (bored != "yes" || bored != "no");
However, that expression will also always evaluate to true, because there is no possible value of bored that can make both bored != "yes" and bored != "no" be false.