Answers for "move letter position using c++ with input"

C++
0

move letter position using c++ with input

#include <iostream>

using namespace std;

int main() 
{
    char c='x';
    int position = 0; //starts from the left most position
    int temp =0;
    cout << "*" << endl;
    cout << "Enter: l (Move Left) or r (Move Right) or x (exit): " << endl;
    cin >> c;

while (c != 'x')
{
    if((c == 'r')||(c=='l'))
    {
        if(c == 'r')
        {
        position++;
        }
        else if(c == 'l')
        {
        if(position==0) 
            position=0;
        else
            position--;
        }
        temp=position;
        while(temp--!=0)
        {
        cout << " "; //print space
        }
        cout << "*" <<endl;
    }   
    else
    {
        cout << "Wrong character entered\n" << endl;
    }
    cout << "Enter: l (Move Left) or r (Move Right) or x (exit): "<< endl;
    cin >> c;
}
return 0;
Posted by: Guest on August-29-2020

Code answers related to "move letter position using c++ with input"

Browse Popular Code Answers by Language