ReverseNumber.cpp (10 pts) Write a program that asks the user to enter an intege
ID: 3833796 • Letter: R
Question
ReverseNumber.cpp (10 pts)
Write a program that asks the user to enter an integer number. The program will display a reversed number.
Place the program in a loop so the user can enter as many time as he wishes by entering “yes” and “no” when asked if he wants to play again.
Write a goodbye message when the user enters “no”.
Sample result:
Enter an integer number: 12345
Reversed number: 54321
Try another number? yes/no: yes
Enter an integer number: -5678
Reversed number: -8765
Try another number? yes/no: no
Goodbye for now!
!!!! Please use C++.
Explanation / Answer
#include <iostream>
using namespace std;
void printReverse(int n)
{
cout << "Reverse number: ";
if (n < 0)
{
n = -1*n;
cout << "-";
}
do
{
cout << n%10;
n = n/10;
}while(n != 0);
cout << endl;
cout << endl;
}
int main()
{
string choice;
do
{
cout << "Enter an integer number: ";
int n;
cin >> n;
printReverse(n);
cout << "Try another? yes/no: ";
cin >> choice;
cout << endl;
} while (choice == "yes");
cout << "Goodbye for now!" << ednl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.