May 12, 2013 at 12:53pm UTC
Deleted post.
Last edited on May 12, 2013 at 1:23pm UTC
May 12, 2013 at 1:00pm UTC
It is not wrong per say. The only concern I see is cin >> gets only one word until you hit space or enter. So, mystring == "How are you?" is ignored. To overcome this problem, you need to use getline().
Last edited on May 12, 2013 at 1:00pm UTC
May 12, 2013 at 1:05pm UTC
"cin.getline ()" right or is it different?
May 12, 2013 at 1:06pm UTC
Also when I typed how are you the program closed even though that should be Bye being typed.
May 12, 2013 at 1:09pm UTC
The call getline doesn't work when used "getline (mystring);"
May 12, 2013 at 1:36pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
#include <iostream>
#include <string>
using namespace std;
string mystring;
double i;
int main()
{
i = 5;
getline(cin, mystring);
if (mystring == "Bye." )
{
system("PAUSE" );
return 0;
}
if (mystring == "How are you?" )
{
cout << " I'm a program, I don't have feelings." ;
}
i = 5;
getline(cin, mystring);
if (mystring == "Bye." )
{
system("PAUSE" );
return 0;
}
if (mystring == "How are you?" )
{
cout << " I'm a program, I don't have feelings." ;
system("PAUSE" );
}
return 0;
}
Last edited on May 12, 2013 at 1:36pm UTC