#include <iostream>
#include <string>
#include <windows.h>
using std:: cout;
using std:: cin;
using namespace std;


int main()
{
 unsigned long n;
 char Answer;
 string mystr;
 do {
 do {    
 cout << " What is your name? ";
 getline (cin, mystr);
 cout << "Hello " << mystr << ".\n";
 cout << "What is one of your hobbies? ";
 getline (cin, mystr);
 cout << "Cool, I also like " << mystr << "!\n";
 cout << "Can you guess my name? ";
 getline (cin, mystr);
 cout << "Haha, good guess " << mystr << " that is funny, trick question I do not have a name! \n";
 cout << "Do you like parkour?(y/n)? ";
	cin >> Answer;

	if(Answer == 'y' || Answer == 'Y')
		cout << "\nYou have been promoted to cool.\n";
		cout << "\nDo you want to do it again? (y/n)";
		cin >> Answer;
  } while (Answer == 'y' || Answer == 'Y');	
	
	if(Answer == 'n' || Answer == 'N')
        cout << "\nDo you know what it is?(y/n)? ";
        cin >> Answer;
        
    if(Answer == 'y' || Answer == 'Y')
        cout << "\nGood.";
        
    if(Answer == 'n' || Answer == 'N')    
       	cout << "\nGo and Google it, then talk to me again.";
       	
  cout << " I am tired, I will go to sleep now. \n";
  cout << "Do you want to do it again? (y/n)";
   cin >> Answer;
  } while ( Answer == 'y' || Answer == 'Y');
  return 0;
}

I need help to make my program loop back in two places. It loops at the end but I do not know how to make it loop in the middle.

cout << "\nDo you want to do it again? (y/n)";
		cin >> Answer;
  } while (Answer == 'y' || Answer == 'Y');

I am a noob and this is the first program i have written without using a book all help and pointers weclome :)

If your if statement has to execute multiple statements, then enclose those in braces.

If your if statement has to execute multiple statements, then enclose those in braces.

Im sorry but i am so much of a noob could you possible show me?

bool will_help = true;
char has_question = 'N';
if (will_help == true) {     // added brace here
   cout << "Do you have another question? (Y/N): ";
   cin >> has_question; 
}                            // and here

By adding braces, you're specifying two statements to execute (print and read) if the condition is true.

bool will_help = true;
char has_question = 'N';
if (will_help == true) {     // added brace here
   cout << "Do you have another question? (Y/N): ";
   cin >> has_question; 
}                            // and here

By adding braces, you're specifying two statements to execute (print and read) if the condition is true.

It did not work it still went down and said "Do you know what it is? (y/n)?"

Oh, I wasn't doing the work for you, I was just giving you a pointer.

if(Answer == 'y' || Answer == 'Y')
		cout << "\nYou have been promoted to cool.\n";
        cout << " Do you want to do it again? \n";
        cin >> Answer;
  } while (Answer == 'y' || Answer == 'Y');

Is what it was.

if(Answer == 'y' || Answer == 'Y')
 {      cout << "\nYou have been promoted to cool.\n";
        cout << " Do you want to do it again? \n";
        cin >> Answer;
}

IS what i changed it to. Is this right?

My apologies, I may have been in error. If they knew what parkour was, did you only want to print "You have been promoted to cool"?

If that's the case, then:

if(Answer == 'y' || Answer == 'Y')
		cout << "\nYou have been promoted to cool.\n";

is fine. The statements following that were indented as well, so I assumed you wanted to group them together. If you did want to group them, then adding the braces is correct, otherwise you can remove them.

    #include <iostream>

      #include <string>

      #include <windows.h>

      using std:: cout;

      using std:: cin;

      using namespace std;





      int main()

      {

      unsigned long n;
      char Answer;
      char A;
      char An;

      string mystr;

     do 

      {

      cout << " What is your name? ";

      getline (cin, mystr);

      cout << "Hello " << mystr << ".\n";

      cout << "What is one of your hobbies? ";

      getline (cin, mystr);

      cout << "Cool, I also like " << mystr << "!\n";

      cout << "Can you guess my name? ";

      getline (cin, mystr);

      cout << "Haha, good guess " << mystr << " that is funny, trick question I do not have a name! \n";




      cout << "Do you like parkour?(y/n)? ";
      cin >> Answer;



      if((Answer=='y')||(Answer=='Y'))
      {


   cout << "\nYou have been promoted to cool.\n";


      cout << "\nDo you want to do it again? (y/n)";

      cin >> A;


      if((Answer=='n')||(Answer=='N'))
      {

      cout<< "\nDo you know what it is?(y/n)? ";
      cin>>An;

      if((An=='y')||(An=='Y'))
      {
      cout << "\nGood.";

       }

      if((An=='n')||(An=='N'))
      {
    cout << "\nGo and Google it, then talk to me again.";



      cout << " I am tired, I will go to sleep now. \n";
      }}}



      cout << "Do you want to do it again? (y/n)";

      cin >> Answer;

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

      return 0;

      }






///just try this one.///

hey! can you help me how apply filestreaming in java.

Hello skiboy209,
You can use

goto

statement.

Thanks that worked the only problem is that when I do n to quit the program it asks me again, then if I do n again it finally quits.

Thanks that worked the only problem is that when I do n to quit the program it asks me again, then if I do n again it finally quits.

Actually it doesnt work, It goes to the do you want to do it again and skips the do you know what it is?

Hello skiboy209,
You can use

goto

statement.

Ok I will try this

skiboy209,

Try consistently indenting your code. It will help you and others more clearly see what is going on. I think your errors involve where you start the nested loop (the second "do {" line), and where you ask if you want to do it again and end the nested loop, but I'm not positive. Try a couple of things, and then re-post the current state of your code if you're still stuck.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.