I have come across this code. Is the use of void an aesthetic issue to indicate that the function has no parameters or does that function really expect something of the void type? Is there a void type (apart from its use to declare a function that returns nothing )?
Home
/
user-77688
Gojira's questions
Gojira
Asked:
2020-03-07 02:29:32 +0800 CST
I have managed to program it in such a way that it inverts the digits of a number not greater than 9999. How can I do it with any integer without having to take into account that restriction? I suspect I have to work with strings.
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int reverse(int numb);
int main()
{
int x;
cout << "Number: " << endl;
cin >> x;
cout << reverse(x) << endl;
cin.ignore();
cin.get();
return 0;
}
int reverse(int numb)
{
int m, c, d, u, newnumber;
m = numb / 1000;
c = (numb - (m * 1000)) / 100;
d = (numb - ((m * 1000) + (c * 100))) / 10;
u = (numb - ((m * 1000)+(c* 100)+( d * 10)));
newnumber = (u * 1000 + d * 100 + c * 10 + m);
return newnumber;
}