Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Christian Ballard
- //COSC 1336 - 001
- //January 28, 2015
- //This program should take the users input of three digits and display them seperatly
- #include<iostream>
- using namespace std;
- int main()
- {
- int number; // Will store the three digit number the user enters.
- int n1, n2, n3; // Will store the extracted digits.
- int number2; // Will store the original user input because the original becomes altered.
- do
- {
- cout << "Please enter a value between 1 and 999. Your may enter '0' to exit." << endl;
- cin >> number;
- number2 = number; // Duplicates the users input.
- if (number == 0) // Checks to see if the user entered a '0'.
- {
- cout << "Thanks for using this program!" << endl;
- }
- else if (number < 0 || number > 999) // Checks to see if the inputed number is in range.
- {
- cout << "That number is invalid please try again." << endl;
- }
- else // If everything above checks out the extraction will proceed.
- {
- //Extraction process
- n1 = number % 10;
- number /= 10;
- n2 = number % 10;
- number /= 10;
- n3 = number % 10;
- number /= 10;
- cout << "The digits in the number " << number2 << " are " << n3 << ", " << n2 << ", and " << n1 << "." << endl;
- }
- } while (number2 != 0); // Checks to see if the program needs to keep running.
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment