im having trouble pin-pointing why my loop continues to execute infinetley. can someone point out what im doing wrong in my dowhile loop?

#include<iostream>
#include<string>
using namespace std;

int main()
{
 
    string command; 
   char again;

   do
   {
    cout << "Welcome to the Intrepeter!" << endl;
    cout << "Please feel free to enter a command." << endl;
    getline(cin, command);  
    
    
    if (command == "function1")
      {
          cout << "will call ....\n";
      }
 
     
    else if (command == "function2")
      {
         cout << "will assemble....\n";
      
      }
      
 
    else if (command != "function1" || "function2")
       {
             cout << "Invalid Entry\n";
             cout << "Please your correct terms\n";
       }
       
             cout << "Would you like to try again?" <<endl;
             cin >> again;
             
       }while(again= 'y' || 'Y' );
     
  
       return 0;   
}

You are not testing if the value is true in the while loop.

}while(again= 'y' || 'Y' );

You need an extra = sign to test if values are true or false.

}while(again== 'y' || again== 'Y' );

i see how i missed that. i fixed that, but this statement:

else if (command != "function1" || "function2")  
     {         
    cout << "Invalid Entry\n";       
      cout << "Please your correct terms\n";  
     }

keeps appearing. it always prints out, regeardless of putting y or Y.

Edited 6 Years Ago by |hex: n/a

Comments
Not reading the posts

i see how i missed that. i fixed that, but this statement:

else if (command != "function1" || "function2")  
     {         
    cout << "Invalid Entry\n";       
      cout << "Please your correct terms\n";  
     }

keeps appearing. it always prints out, regeardless of putting y or Y.

Its the same problem as stated above by Akill 10

Edited 6 Years Ago by gerard4143: n/a

i see how i missed that. i fixed that, but this statement:

else if (command != "function1" || "function2")  
     {         
    cout << "Invalid Entry\n";       
      cout << "Please your correct terms\n";  
     }

keeps appearing. it always prints out, regeardless of putting y or Y.

Well, the only reason it would print, is if the command string is not equal to either of those strings(You have to change that if statement like the other one). A reason it could do this is that you enter the wrong command the first time, so it goes into this if statement, but the program will not ask you to enter a new string, it will keep the previous one. Therefore, entering y or Y will have no affect, as the compiler will assume you want the same command as before and will therefore be incorrect and keep going into this else..if block. Try adding this line inside that else..if block:

else if (command != "function1" || "function2")  
     {         
    cout << "Invalid Entry\n";       
      cout << "Please your correct terms\n";
    command.clear();//add this
     }

Edited 6 Years Ago by Akill10: n/a

This question has already been answered. Start a new discussion instead.