reversed number

Sep 20, 2015 at 8:24pm
closed account (ozyMoG1T)
Write your question here.


I tried to make the reversed number work.
Would someone please help me?

Thank you.
Last edited on Sep 21, 2015 at 4:04pm
Sep 20, 2015 at 8:30pm
can you read the number as a string?

Then you can read the string like.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>

using namespace std;

int main() {
    string input;
    cout << "Please enter in the string you want to reverse:" << endl;
    cin >> input;
    input = string (input.rbegin (), input.rend ());
    cout << input;
    return 0;

}

Sep 20, 2015 at 8:32pm
closed account (E0p9LyTq)
reverse() doesn't do what you think it does. It works on containers, vector for instance.

http://www.cplusplus.com/reference/algorithm/reverse/

You need to create your own function to reverse the digits.
Last edited on Sep 20, 2015 at 8:33pm
Topic archived. No new replies allowed.