Hello all,
Thank you ahead of time if anyone answers this.
I am new to c++ and am having some difficulty understanding my assignment.
I wrote some code that does what the teacher has requested but according to her it does not utilize a function. I know that I have to call a function and that the function should not have to have user input to work but I don't really know how to modify my existing code to implement a function.
(I thought I was, as the program does what it is supposed to do, just not the way she wants it to be done.) PLEASE HELP!! HERE IS THE CODE I HAVE
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int reverse(); //function prototype for number reversal
int main() //begins program execution
{ int a; //number reversed
a = reverse();
cout << "The reversed number is " << a << endl; //final output
return 0; //end program
}
int reverse() //function
{
int x, y, z = 0; //initialize parameters
cout << "Enter an integer to be reversed: "; //initial number
cin >> x; //input number
while (x > 0){ //while conditions
y = x%10;
x = x/10;
z = 10 * z + y;
}
return z; //return value
} //end reverse function