turtle user input question

Hey again everybody, I have this simple code here, and a very simple question.
When I run this code I can either choose to type l, r or f, each letter activates a sentence, like type l, the turtle goes left and so on...
But I can only type a letter once and then the code stops..

I would like to repeatedly type, l, r or f many times, as long i feel like without the code stops. I just want the code to start over and over agaib. I know its a silly question, but can someone help me.

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
37
38
// my stuff

// as the player of this game you have three choices, move the turtle forward and
// choose its direction - Either left or right

#include <iostream>
using namespace std;

int main(){

char myresponse; // I use here char because i want to write a command and not type an int

std::cout << "your turtle just woke up, what should it do?" << std::endl;

cin >> myresponse;

// Here I will use conditionals

if (myresponse == 'l')
{
// do something
std::cout << "the turtle goes left" << std::endl;
} 

else if (myresponse == 'r')
{
std::cout << "the turtle goes right" << std::endl;
// do something else
}

else if (myresponse == 'f')
{
std::cout << "the turtle steps forward" << std::endl;
// do this instead
}

}

1
2
3
4
do
{
    //put lines 15-35 from your code here
}while( myresponse != 'Q' );
Last edited on
Topic archived. No new replies allowed.