i c i c thx for the reply
can you give me some ideas of how to write the year 1782 for eg?
cause wont i have to create a eleven to nineteen dictionary for the program?
any samples?
i c i c thx for the reply
can you give me some ideas of how to write the year 1782 for eg?
cause wont i have to create a eleven to nineteen dictionary for the program?
any samples?
and i dont know why the output is
fortythree hundrendone
i cant get the twenty out for some reasons???
but let say 1782
how does the divison work on that?
1782/1000 and then ???
lol im so confused
PLEASE do you mind giving me an example
PLEASE literally begging you
Missed one: that should be a divide by 10 in the twenty, not a divide by 100.
I don't know what else to say except you've already posted the example. But just because:
et cetera.Code:int number = 4321; int thousands = number/1000; int hundreds = (number%1000)/100; int tens = (number%100)/10; int ones = number%10; if (thousands == 1) printf("One"); else if (thousands == 2) printf("Two"); else if (thousands == 3) printf("Three"); else if (thousands == 4) printf("Four"); else if (thousands == 5) printf("Five"); else if (thousands == 6) printf("Six"); else if (thousands == 7) printf("Seven"); else if (thousands == 8) printf("Eight"); else if (thousands == 9) printf("Nine"); if (thousands) printf(" thousand ");
but they want it in this format:
Enter year and month: 1980 2
nineteen hundred eighty
has three hundred and sixty six (366) days
February has 29 days
% ./assn1
Enter year and month: 1980 3
nineteen hundred eighty
has three hundred and sixty six (366) days
March has 31 days
% ./assn1
Enter year and month: 2000 2
twenty hundred
has three hundred and sixty six (366) days
February has 29 days
So if you had read the example that would be a long, but trivial, change.
so let say 1782
wouldn't it be
seventeen hundred eighty two
but then i cant seperate 17 from the 1782 with the normal method....
That implies that you should break it up into: hundreds, tens, ones.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
but i break it into hundreds it might be convienet for years from 1700-1900
but let say 8999 it will be hard doing hundreds
It is as hard as doing 89.but let say 8999 it will be hard doing hundreds
There are two possible solutions that come to mind. One involves a massive bunch of if-else statements to handle the numbers from 0 to 99 inclusive. This would be used first for the century, and then for the decade and individual year. The other solution is to check if the first number is a 1. If it is, then you use "ten", "eleven" etc. If not, you just use "twenty", "thirty" etc.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
thx for the reply
can u show me an if statement for the yr 1782 for eg
which would convert to seventeen hundred and eighty two?
I am not sure whether you are supposed to use character arrays for your assignment, but nevertheless, all you need is
then, get the hundreds, tens and ones part of the yearCode:const char *unitStr[10] = { // string constants for unit places "Zero", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" }; const char *teenStr[10] = { // string constants for teen numbers "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "Seventeen", "Eighteen", "Nineteen", }; const char *tenStr[10] = { // string constants for tens places "Zero", "Ten", "Twenty", "Thirty", "Forty", "Fifty", "Sixty", "Seventy", "Eighty", "Ninety", };
From this point onwards, you need a bunch of if statements to see if the variable hundreds is single digit, b/w 11 and 19 (inclusive) or greater than 19 to get the appropriate output string :-). The same logic goes with tens and ones.Code:hundreds = number/100; tens = (number % 100)/10; ones = (number %100)%10;
I am tempted to post my code but its against homework rule
cheers
maverix
thx for the reply
...apparently we can only use a lot of if statements so i think we aren't allow to use character array
so so far im stuck on how to do a year like 1782 using only IF and IF else statemtns
any examples will be GREATLY appreicated... im wasting far 2 much time on this
break the year 1782 into hundreds, tens and ones (as shown in my previous post)
but this is only for 1782Code:break the year 1782 into hundreds, tens and ones (as shown in my previous post) if(hundreds == 17) printf("Seventeen Hundred"); if(tens == 8) printf(" and Eighty"); if(ones == 2) printf(" Two");
you would be doomed if you follow this approach coz you have to deal with a lot many years
good luck
maverix