Apr 9, 2013 at 3:49am UTC
write a compile and run a c++ program to reverse the digits of a positive integer number .use a do-while statement and continuously strip off and display the numbers units digit
Apr 9, 2013 at 3:55am UTC
please im a beginner i have no clue what to do
Apr 9, 2013 at 4:04am UTC
Have you tried turning it off and on again?
Apr 9, 2013 at 4:09am UTC
I recommend paying attention in class and doing whatever required reading there might be.
Apr 9, 2013 at 4:09am UTC
yes i did Easton multiple times. how would you go by writing the program ?
Apr 9, 2013 at 4:55am UTC
You COULD write it like this. I'll leave "explaining this code atrocity to the instructor" as an exercise for the OP.
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 31
#include <iostream>
#include <string>
#include <sstream>
std::string makePalindrome(std::string inStr)
{
std::stringstream sstr;
sstr << inStr;
for (std::string::reverse_iterator rit = inStr.rbegin();
rit != inStr.rend();
++rit)
{
sstr << (*rit);
}
return sstr.str();
}
int main()
{
std::string userInput;
std::cout << "Enter a number to reverse: " ;
std::getline(std::cin, userInput);
do
{
std::string newString = makePalindrome(userInput);
std::cout << newString.substr(userInput.size()) << "\n" ;
} while (0);
return 0;
}
Last edited on Apr 9, 2013 at 5:11am UTC
Apr 9, 2013 at 4:55am UTC
I would go about it by pasting the source code I should have made, and clearly explaining where the error in my source code is, and hoping that someone will help me after this post.