Hi guys, so in my program I need to have the user enter in 1 cin statement their height in decimal-like format, ie 5 feet 10 inches = 5.10 . I'm then required to take this piece of information and display the user's total height in inches. I understand that 12 inches = 1 foot so it would be (5x12) + 10 = 70 inches, and I could do that easily if I had the user enter in the feet/inches separately. I just don't understand how to perform it when its entered as just 1 piece of information.
Okay i'll bite, I don't know in the slightest how or where i'm suppose to apply that code. I've checked all my notes and our book. We're suppose to be inputting in the decimal as 1 piece of code..
cin >> height...The challenge is to separate the feet from the .inches....
Given a decimal value like 5.10, there exists a function (hint hint) that will allow you to get either that 5 or that 10 by itself.
How does your professor say you should distinguish 5'10" from 5'1". Because the naïve way to input both would be "5.1". (The correct way, according to what you've given us, would be 5.1 and 5.01, respectively.)
If we assume that no one is more than 10 feet tall, then you can use std::isdigit with each character. This will determine the feet, then skip whatever after that until the next digit is found (possibly two digits), which will be the inches. Then the user can freely type in 5.10 or 5'10 or 5'10" or 5 foot 10 or 5 feet 10 or whatever and the feet and inches will always be obtained using std::stoi (and checking that the inches is less than 12).