Moving Robot C++

The walking robot based on a series of orders given , each command is one of the following types:
- A reference < , which means that on the robot to move to the right step.
- A reference > , which means that on the robot to move to the left of the step.
Can you identify the robot site after the implementation of n from the command ? Android site initially is 0 , when you move to the right , the location is increased by one , and when you move to the left , it decreases by 1 .

Input:
Input contains a number n , and represents the number of orders, followed by n symbols , each symbol is either > or < , detailing all symbols distance.
Output:
Print robot site after the implementation Given commands on one line , do not forget to print endl at the end of each line.
Example Input:
7 > < < > < < <
Example Output:
-3
Are you having trouble coming up with an implementation for the problem?
You can tell us what you're having trouble with and we can help you, but most of us won't just pop out a solution.

What have you tried so far? What're you having trouble with?
Hi,

Welcome to cplusplus.com.... Please read the guidelines, this is not a homework site, you have to provide us with what you did/tried in your code and we may help you....

Just directly posting question like a robot won't get you any answers....

So please show us what you did/tried
My apologies, this is my first time on this website, so thanks for the heads up.
I am having a problem reading the characters (<, >) and deciding whether to move forward or backward. I am also having trouble with the integers, how do I output a negative sign? This is what I have done so far, it is terrible, so please don't judge! Thank you!

#include <iostream>
using namespace std;

int main() {
char a;
int b;
cin >> a;
if (a=">"){
b = b+1
}
else
b=b-1

return 0;
}
If it's an integer and it's negative, it'll print the '-' sign for you. You don't have to do that yourself.

The only thing you have to worry about is reading in 'n', and then reading n more characters.

n is an integer that the user enters, so you should make another integer to store it. You already know that there will be exactly n orders, so you only have to read those in that many times.
Since a is a character, you should compare it to other characters using single quotes '', like '>' or '<'
You should use if (a == '>')
And make sure to use == for comparison. = makes assignments, so it will change the value of a if you use =. == compares the left and right arguments.

You have the right idea about counting, but change if (a = ">"), "" is used for strings, and the = will actually change the value of a instead of comparing it something else.

You should initialize your variables, because right now b will just have some junk value that was in memory, as will c.
Just set some initial value when you declare your variables
1
2
int b = 0; //b should start counting from 0, shouldn't it?
char c = 'n'; //Or whatever initial value you want it to have 


Hint: You can put the cin for reading in the orders in a loop. How many times should that loop execute?
closed account (48bpfSEw)
If you like to create a simulation of roboter movements (2D)...

I have wrote a little app based on the command concept of LOGO in Java:

There are two circles and a roboter which is moving straight. If it leaves the outer circle or enters in the inner circle it turns around in a given degree. These are the patterns after some interations:

https://necips8.wordpress.com/2016/03/22/bewegungsbahn-eines-roboters/

Topic archived. No new replies allowed.