-
C++ program help
I need to write a simple algorithm for converting numbers into english words. The numbers cannot be below -2,000,000,000 or above 2,000,000,000. If anyone can help it would certainly help me a lot.
Here is what I have so far.
#include <iostream>
using namespace std;
int main ()
{
int num;
cout<<"Enter an integer (or zero to exit)";
cin>>num;
while ((num>-2,147,483,647)&&(num<2,147,483,647)){
if (num>1,000,000,000){
cout<<num/1,000,000,000;}
if (num>1,000,000){
cout<<num/1,000,000;}
if (num>1,000){
cout<<num/1,000;}
if (num>100){
cout<<num/100;}
}
return 0;
}
-
Please don't ask people to do all your work for you, See the announcement on Homework at the top of the forum to see what is acceptable ro PM. Basically people are happy to help, but they're not going to do it all for you. Show us what you've got, show your code (using code tags), or where you're confused and someone will be happy to help you I'm sure.
-
in my opinion he wasn't asking for a program, but for help. I don't see any need to jump on him unless he came out and said "write my program", but he didn't, he said "any help would be nice" (not exact quote).
Just my two cents.
-
It sounds like you need an array of string variables... Each string would be one word long and each index-number points a word.
Because the string itself is an array, you will actually have a two-dimensional array.
-
Do you mean, for instance, that 10023 should be converted into "Ten Thousand twenty three" ?
If this is the case, you would need to determine what the smallest number of words you would need are, and store them away, in an array (or in a few arrays). For instance, you need the following for sure: "one", "two", "three", "four", ...."twenty", "thirty", etc.
You don't need things like "twenty one", since it's a combination of two other numbers you already have.
Notice also that 10023 % 10 is 3, and it would be very convenient if an array index 3 was the word "three". Then if you stored 10023/10, you would be left with 1002, and you could repeat this procedure to get the next array index (2), which might be in another array, where 2 conveniently maps to "twenty". Perhaps you will know that if you are one the first loop iteration, you are in the one's array, and the second loop is the tens array, and the third loop iteration is the hundreds array, Etc., Etc. Just a thought, and I'm not sure if all this works out perfectly, because I really haven't thought it through completely. So there is still some work left for you.