Search
 
SCRIPT & CODE EXAMPLE
 

CPP

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
" << endl;
    }
    cout << "Enter: l (Move Left) or r (Move Right) or x (exit): "<< endl;
    cin >> c;
}
return 0;
Comment

PREVIOUS NEXT
Code Example
Cpp :: KUNG FU HUSTLE 
Cpp :: sort vector from smallest to largest 
Cpp :: how to compile with libstdc++ fedora 
Cpp :: c++ multiple if conditions 
Cpp :: how are c++ references implemented 
Cpp :: traverse string in cpp 
Cpp :: play roblox vr on quest 2 
Cpp :: for llop in c++ 
Cpp :: how to move your chrector in unity 
Cpp :: left margin c++ 
Cpp :: return multiple objects from a function C++ using references 
Cpp :: run program until ctrl-d c++ 
Cpp :: second smallest element using single loop 
Cpp :: Arduino C++ servomotor random moving 
Cpp :: fasdf 
Cpp :: all in one c++ 
Cpp :: How to make an array dynamically using pointers 
Cpp :: Character convert c++ 
Cpp :: std::random_device 
Cpp :: castin in C++ 
Cpp :: cplusplus 
Cpp :: c++ operators 
Cpp :: get player pawn 
Cpp :: font family slick 
Cpp :: how to make a goto area in c++ 
Cpp :: multiply two arbitrary integers a and b (a greater than b) 
Cpp :: inverse lerp c++ 
Cpp :: c++ multi-dimensional arrays 
Cpp :: for statement in c++ 
Cpp :: C++ Counting 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =