Last active
July 1, 2018 18:41
-
-
Save xseano/d4d9cea7c6dda3bffe0eb7fe1b1fb12c to your computer and use it in GitHub Desktop.
Chapter 6 #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "tgmath.h" | |
| // For the sake of not having to prepend datatypes with std:: :P | |
| using namespace std; | |
| int main () | |
| { | |
| cout << "Enter a number 1-4 digits: "; | |
| string num; | |
| cin >> num; | |
| bool thousand = false; | |
| bool hundred = false; | |
| bool ten = false; | |
| bool one = false; | |
| int thousandCount = 0; | |
| int hundredCount = 0; | |
| int tenCount = 0; | |
| int oneCount = 0; | |
| int number = stoi(num); | |
| string howMany = num + " is "; | |
| if (number / 100 >= 10) | |
| { | |
| thousand = true; | |
| thousandCount = (number / 100) / 10; | |
| number -= thousandCount * 1000; | |
| } | |
| if (number / 10 >= 10) | |
| { | |
| hundred = true; | |
| hundredCount = (number / 10) / 10; | |
| number -= hundredCount * 100; | |
| } | |
| if (number / 10 >= 1) | |
| { | |
| ten = true; | |
| tenCount = (number / 10) / 1; | |
| number -= tenCount * 10; | |
| } | |
| if (number / 1 < 10) | |
| { | |
| one = true; | |
| oneCount = (number / 1) / 1; | |
| number -= oneCount * 1; | |
| } | |
| if (thousand == true) | |
| { | |
| howMany.append(to_string(thousandCount) + " thousand "); | |
| } | |
| if (hundred == true) | |
| { | |
| howMany.append(to_string(hundredCount) + " hundred "); | |
| } | |
| if (ten == true) | |
| { | |
| howMany.append(to_string(tenCount) + " tens "); | |
| } | |
| if (one == true) | |
| { | |
| howMany.append(to_string(oneCount) + " ones "); | |
| } | |
| cout << howMany << endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment