Forum: Geek Forum Topic: c++ data types started by: a.out Posted by a.out on Sep. 26 2001,23:43
I have to write a program for my c++ course, and one of the requirements is to allow the user to enter a number of feet, and the program should output the WHOLE number of miles in that number of feet, and then the number of miles left over. This is very simply to do, simply doing integer division, and then doing a feet\%5280 (modulus) operation to get the remainder. However, my instructor decided to add a requirement that the number that can be entered by the user can be as long as 13-14 digits. So, what type of variable do I use? It needs to be integral to use the \% operator, so no floats or doubles. I did mess around some, and I found that a "double long" was a valid type, which was basically twice as long as a "long" (4 bytes on the school's systems, so the double long was 8 bytes). However, this data type doesn't seem to work with the modulus operator. I am at a loss of what type to use. Any suggestions? Edit: BTW, we are using Codewarrior 4 or something on WinNT This message has been edited by a.out on September 27, 2001 at 06:44 PM Posted by @$$h0l3 on Sep. 27 2001,00:44
Well, if the integer math works (i.e. miles = input / 5280), miles will return a whole number. Just do feet = input - miles * 5280.
Posted by a.out on Sep. 30 2001,04:47
I finally found a variable type that works with this. It's strange, because I hadn't ever heard of it before, and neither had my instructor. It's "unsigned long long". Weird. But it worked...
Posted by damien_s_lucifer on Oct. 02 2001,16:31
"long long" has been a valid data type for a while now. It's generally an integer that uses 64 bits instead of 32.
|