Screen should output this:
Enter Five Digit number: 12345
Ones digit is: 5
Tens digit is: 4
Hundreds digit is: 3
Thousands digit is: 2
Ten-thousands digit is: 1
Press any key to continue
#include <iostream> // required to perform C++ stream I/O
using namespace std; // for accessing C++ Standard Library members
// function main begins program execution
int main()
{
//define variables
int num; //stores five digit numbers
int onesplace;
int tensplace;
int hundredsplace;
int thousandsplace;
int ten_thousandsplace;
//prompt user to input a five digit number
cout <<"Input a five_digit number:";
cin >> num; //read user input
onesplace= num%10; //returns digit in ones place
cout <<"\nOnes digit is:"<< onesplace;
num =num/10; //returns digit in tens place
tensplace= num;
cout <<"\nTens digit is:"<< tensplace;
num =num/10/10; //returns digit in hundreds place
hundredsplace= num;
cout <<"\nHundreds digit is:"<< hundredsplace;
num =num/10/10/10; //returns digit in thousands place
thousandsplace= num;
cout <<"\nThousands digit is:"<< thousandsplace;
num =num/10/10/10/10; //returns digit in ten_thousands place
ten_thousandsplace= num;
cout <<"\nTen_Thousands digit is:"<< ten_thousandsplace;
return 0; // indicate that program ended successfully
} // end function
But it is not printing this way.Thanks
Edited by WingedPanther, 15 September 2011 - 07:07 AM.
add code tags (the # button)


Sign In
Create Account


Back to top









