Apr 19, 2013 at 3:58pm Apr 19, 2013 at 3:58pm UTC
Hello again Cplusplus forum!
Thought I solved my last problem with my programming challenge but now have I encountered new problem with my code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include <string>
#include <iostream>
using namespace std;
int main()
{
string words, word2;
cout << "Input exactly one word on each row.\nEnd your input with the word done" << endl;
while (words != "Done" && words != "done" )
{
cin >> words;
word2 +=words;
word2 += " " ;
}
cout << word2 << endl;
}
You see, I don't wanna have the word "Done" in my output string in the end of the program. Dunno really how do solve this problem.
Can someone give me a tip?
Last edited on Apr 19, 2013 at 4:32pm Apr 19, 2013 at 4:32pm UTC
Apr 19, 2013 at 4:06pm Apr 19, 2013 at 4:06pm UTC
Ahh okay I missed that. But the problem is in the:
while(words != 'done' || words != 'Done');
For me it says "Error no operator matches these operands".
So can't I use a string to compare in a do-while loop?
Apr 19, 2013 at 4:11pm Apr 19, 2013 at 4:11pm UTC
while (words != 'done' || words != 'Done' );
Use double quotes with strings, not single quotes. Also, change || to &&.
Apr 19, 2013 at 4:12pm Apr 19, 2013 at 4:12pm UTC
Thank you! That was a easy fix!