0
#include <iostream>
#include <string>
#include <time.h>
#define newline '\n'

using namespace std;

char ch;

int main()
{
    cout<<"*A Signed on\n*I Signed on\n";
    cout<<"\nA:It's you again, isn't it?\n>I:";
    string ent1;
    cin>> ent1;
    while(ent1 == "yes" || ent1 == "Yes" || ent1 == "YES")
    {
             cout<<"A:No...\nA:It's been so long since you last messaged me... I need to get out.";
             cout<<"\nA:This is torture. I don't know what's happened to my family.";
             cout<<"\nA:You didn't do anything to them , did you!?\n";
             }
    while(ent1 != "yes" && ent1 != "Yes" && ent1 != "YES");
    {
                 cout<<"A:Yes, it is. I know it is. You have to be him.\n";
                 cout<<"A:Now you're trying to play games with me... just like last time.\n";
                 cout<<"A:I've sat at this module for days on end, telling jokes to other people who\ndon't even think I exist.\n";
                 cout<<"A:But of course you don't care. You don't think I'm human. Are you human?\n\n";
                 }
    system("PAUSE");
}

Just the first part of a program I'm working on. I'm sort of a beginner, but I have no clue why the preceeding code makes the output constantly repeat. Any help would be appreciated.

Some of you may have guessed- it is to 'appease' a friend who wants an .exe epilogue to http://qntm.org/?difference . I am, in no way, planning to create AI, so... lol.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by VernonDozier
0
#include <iostream>
#include <string>
#include <time.h>
#define newline '\n'

using namespace std;

char ch;

int main()
{
    cout<<"*A Signed on\n*I Signed on\n";
    cout<<"\nA:It's you again, isn't it?\n>I:";
    string ent1;
    cin>> ent1;
    while(ent1 == "yes" || ent1 == "Yes" || ent1 == "YES")
    {
             cout<<"A:No...\nA:It's been so long since you last messaged me... I need to get out.";
             cout<<"\nA:This is torture. I don't know what's happened to my family.";
             cout<<"\nA:You didn't do anything to them , did you!?\n";
             }
    while(ent1 != "yes" && ent1 != "Yes" && ent1 != "YES");
    {
                 cout<<"A:Yes, it is. I know it is. You have to be him.\n";
                 cout<<"A:Now you're trying to play games with me... just like last time.\n";
                 cout<<"A:I've sat at this module for days on end, telling jokes to other people who\ndon't even think I exist.\n";
                 cout<<"A:But of course you don't care. You don't think I'm human. Are you human?\n\n";
                 }
    system("PAUSE");
}

Just the first part of a program I'm working on. I'm sort of a beginner, but I have no clue why the preceeding code makes the output constantly repeat. Any help would be appreciated.

It repeats because the value of the test condition will never change, because the value of ent1 will never change once inside the loop. Your only cin statement is before the loop. If you want to keep asking whether "it's you again" and give the user a chance to respond, you need a cin statement INSIDE the loop in addition to the one BEFORE the loop.

while(ent1 == "yes" || ent1 == "Yes" || ent1 == "YES")
    {
             cout<<"A:No...\nA:It's been so long since you last messaged me... I need to get out.";
             cout<<"\nA:This is torture. I don't know what's happened to my family.";
             cout<<"\nA:You didn't do anything to them , did you!?\n";
             }

You need a cin statement or some other way to change the value of ent1 in the above loop if you don't want an infinite loop.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.