move letter position using c 2b 2b with input

Solutions on MaxInterview for move letter position using c 2b 2b with input by the best coders in the world

showing results for - "move letter position using c 2b 2b with input"
Karl
05 Aug 2017
1#include <iostream>
2
3using namespace std;
4
5int main() 
6{
7    char c='x';
8    int position = 0; //starts from the left most position
9    int temp =0;
10    cout << "*" << endl;
11    cout << "Enter: l (Move Left) or r (Move Right) or x (exit): " << endl;
12    cin >> c;
13
14while (c != 'x')
15{
16    if((c == 'r')||(c=='l'))
17    {
18        if(c == 'r')
19        {
20        position++;
21        }
22        else if(c == 'l')
23        {
24        if(position==0) 
25            position=0;
26        else
27            position--;
28        }
29        temp=position;
30        while(temp--!=0)
31        {
32        cout << " "; //print space
33        }
34        cout << "*" <<endl;
35    }   
36    else
37    {
38        cout << "Wrong character entered\n" << endl;
39    }
40    cout << "Enter: l (Move Left) or r (Move Right) or x (exit): "<< endl;
41    cin >> c;
42}
43return 0;