Need help figuring out a reversedigit program, super close to solution

Hello people, thank you for viewing. I am doing a homework assignment where the prompt the teacher has given us states "Write a function, reverseDigit, that takes an integer as a parameter and returns the number with its digits reversed." So I've cranked out the math manually, due to the teacher getting distracted during lectures and digressing into off topic comments and stories randomly. I had him take a first look at the code and he mentioned i didn't create a function named reversedigit. I'm confused as to what i'm supposed to take out, but i'd assume the longnumber line all the way to number = number / 10;. I'm flustered and I needed to walk away for a minute, so any advice would be good advice. Thank you all again for your time and help.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 #include <iostream>
#include <string>

using namespace std;

int main(void)
{
	long number, remainder, reverseNumber = 0;
	char hang;

	cout << "Enter the number: ";
	cin >> number;

	while (number)
	{

		remainder = number % 10;


		reverseNumber = (reverseNumber * 10) + remainder;

		number = number / 10;
	}

	cout << "Reversed number = " << reverseNumber << endl;

	system("pause");

	return 0;
}
line 5: Build your prototype ie: int reverseDigit ( int );
line 8: move remainder and reverseNumber inside that function along with lines 14 <-> 23 inclusive.
Line 25: reverseNumber can be changed to reverseDigit (number)

Start this at line 32
1
2
3
4
int reverseDigit ( int Number ) {
    // Stuff from above
    return reverseNumber
}

Last edited on
Your method will only work for small numbers less than 2147483647 forward and backwards. For a larger number you would want to use a string.
Topic archived. No new replies allowed.