google-site-verification: googlebaca44933768a824.html My little c++ program - Old Royal Hack Forum

Announcement

Collapse
No announcement yet.

My little c++ program

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    My little c++ program

    I have this kind of code:
    Code:
    #include <iostream>
    
    int main () {
    	char answer;
    	std::cout << "Am I best? <y/n>" << std::endl;
    	do {
    	std::cin >> answer;
    	if (answer=='y' || answer=='Y')
    		std::cout << "Good!" << std::endl;
    	else if (answer=='n' || answer=='N')
    		std::cout << "You are an idiot." << std::endl;
    	else
    		std::cout << "Answer the question right, idiot." <<std::endl;
    	} while (answer!='y' || answer!= 'n' ||answer!='Y' || answer!= 'N');
    	system("pause");
    	return 0;
    }
    It works, but if I input "ynynyn", without quotes, the cmd will return:

    Code:
    Good!
    You are an idiot.
    Good!
    You are an idiot.
    Good!
    You are an idiot.
    how could I avoid this?
    ok bai

    #2
    Re: My little c++ program

    this made me laugh hard lol, don't know how to help thou?!?!;)

    Good!
    You are an idiot.
    Good!
    You are an idiot.
    Good!
    You are an idiot. hahahah

    Comment


      #3
      Re: My little c++ program

      Originally posted by udevil_666 View Post
      this made me laugh hard lol, don't know how to help thou?!?!;)

      Good!
      You are an idiot.
      Good!
      You are an idiot.
      Good!
      You are an idiot. hahahah
      yeah it's pretty insane :D and when i input something like "kkkkkkkk" it will just return:
      Code:
      Answer the question right, idiot.
      Answer the question right, idiot.
      Answer the question right, idiot.
      Answer the question right, idiot.
      Answer the question right, idiot.
      Answer the question right, idiot.
      Answer the question right, idiot.
      Answer the question right, idiot.
      ok bai

      Comment


        #4
        Re: My little c++ program

        Cheap and not perfect solution, but this kind of fixes it
        Code:
        #include <iostream>
        
        int main () {
        	char answer;
        	std::cout << "Am I best? <y/n>" << std::endl;
        	do {
        	std::cin >> answer;
        	if (answer=='y' || answer=='Y'){
        		std::cout << "Good!" << std::endl;
        		break;
        	}
        	else if (answer=='n' || answer=='N'){
        		std::cout << "You are an idiot." << std::endl;
        		break;
        	}else{
        		std::cout << "Answer the question right, idiot." <<std::endl;
        		break;
        	}
        	} while (answer!='y' || answer!= 'n' ||answer!='Y' || answer!= 'N');
        	system("pause");
        	return 0;
        }

        Comment


          #5
          Re: My little c++ program

          Originally posted by Rudolf123 View Post
          Cheap and not perfect solution, but this kind of fixes it
          Code:
          #include <iostream>
          
          int main () {
          	char answer;
          	std::cout << "Am I best? <y/n>" << std::endl;
          	do {
          	std::cin >> answer;
          	if (answer=='y' || answer=='Y'){
          		std::cout << "Good!" << std::endl;
          		break;
          	}
          	else if (answer=='n' || answer=='N'){
          		std::cout << "You are an idiot." << std::endl;
          		break;
          	}else{
          		std::cout << "Answer the question right, idiot." <<std::endl;
          		break;
          	}
          	} while (answer!='y' || answer!= 'n' ||answer!='Y' || answer!= 'N');
          	system("pause");
          	return 0;
          }
          thanks,

          also
          Code:
          } while (answer!='y' || answer!= 'n' ||answer!='Y' || answer!= 'N');
          should be replaced with
          Code:
          } while (answer!='y' && answer!= 'n' && answer!='Y' && answer!= 'N');
          ok hmm i'm learning!
          ok bai

          Comment

          Working...
          X