25-07-2006, 12:29 PM
|
#1 (permalink)
|
|
Right Off the Assembly Line
Join Date: May 2006
Posts: 30
|
a small c problem
i have 2 questions in my book for which i am not able to decide on the exact solution..
? 1- write a program to accept any number upto 6 digits and print that in a string.
Eg:
input number 1034
output string one thousand thirty four
? 2- write a program to accept any date in numbers annd print that in string
Eg
input date: 19/3/96
output string nineteen march ninety six.
|
|
|
|
Advertisements. Register and be a member of the community to get rid of them.
|
|
Advertisement
|
|
25-07-2006, 02:51 PM
|
#2 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
Re: a small c problem
Since it's probably a homework question, I'm not going to give the answer as code.
In both, you need to extract the digits one by one, and display accordingly.
Use a loop to extract the digits, and store them in variables. Then output them after the loop has finished.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
|
|
|
25-07-2006, 03:56 PM
|
#3 (permalink)
|
|
In The Zone
Join Date: Apr 2004
Location: Paris
Posts: 313
|
Re: a small c problem
use of arrays,pointers will help you .. had done both programs in past.. try it own dear
__________________
I AM REBEL
|
|
|
25-07-2006, 05:15 PM
|
#4 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
Re: a small c problem
I am glad you guys didn't give out the code  This surely is a homework problem! Solve it on your own man! These guys have given you enough hints!
I have done this in COBOL when I learnt it  You can't do it in C?  Try it. Its easy. You can do it.
|
|
|
26-07-2006, 12:28 AM
|
#5 (permalink)
|
|
Right Off the Assembly Line
Join Date: May 2006
Posts: 30
|
Re: a small c problem
hey guys @ least tell me how to go abt that 18 ,19 etc nos...
ie how do i print the appropriate string saying eighteen ,or one or two,,,
for all the dates in a month!!!
|
|
|
26-07-2006, 09:08 AM
|
#6 (permalink)
|
|
Legen-wait for it-dary!
Join Date: Dec 2004
Location: Chennai
Posts: 2,471
|
Re: a small c problem
get each number and its place(ones place, tens place, hundreds place etc) and write a function to convert a number to text (basic like 9-nine) and add suffixes based on the place. remember there are lots of exceptions in this pogram because 18 is eight-een and 17 is seven-teen but 11 is not one-een. get what I'm saying? this confusion is only in 2 digit numbers till 20, so from that its easy
|
|
|
26-07-2006, 09:17 AM
|
#7 (permalink)
|
|
Console Junkie
Join Date: Jun 2006
Location: USA
Posts: 991
|
Re: a small c problem
Are you suggesting using the % (reminder tag?)
Aditya
|
|
|
26-07-2006, 10:25 AM
|
#8 (permalink)
|
|
Right Off the Assembly Line
Join Date: May 2006
Posts: 30
|
Re: a small c problem
Quote:
|
Originally Posted by dheeraj_kumar
get each number and its place(ones place, tens place, hundreds place etc) and write a function to convert a number to text (basic like 9-nine) and add suffixes based on the place. remember there are lots of exceptions in this pogram because 18 is eight-een and 17 is seven-teen but 11 is not one-een. get what I'm saying? this confusion is only in 2 digit numbers till 20, so from that its easy
|
no ...u r not right!!! cos i have to print it as eleven for 11 , and not split the numbers as one one or for that matter 18 as eight-een
any numbershould be printed as we read it
like eighteen, 25 as twenty five itself and not like two-five as stated by u!!!
c this is the problem..and i do not want to use some stupid switch case or some else if ladders to print it appropriately!!!
|
|
|
26-07-2006, 10:37 AM
|
#9 (permalink)
|
|
Alpha Geek
Join Date: Jan 2005
Location: earth
Posts: 804
|
Re: a small c problem
Quote:
|
Originally Posted by tuxfan
I am glad you guys didn't give out the code  This surely is a homework problem! Solve it on your own man! These guys have given you enough hints!
I have done this in COBOL when I learnt it  You can't do it in C?  Try it. Its easy. You can do it.
|
hi tuxfan, so u know to code programs in cobol , cud u pls suggest me some ebooks, or tutorials on cobol cause i'm also learnin COBOL, for AS 400 and mainframes.
__________________
signature??? :???: Let Me Think About It!!!:-D
|
|
|
26-07-2006, 11:40 AM
|
#10 (permalink)
|
|
Human Spambot
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
|
Re: a small c problem
Extract the last two digits: for one to twenty they have to have separate switches, for above twenty, you put one switch for each of the two digits. Then, go to the next digit for hundred, and so on...
Arun
|
|
|
26-07-2006, 02:37 PM
|
#11 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
Re: a small c problem
Quote:
|
Originally Posted by paul_007
hi tuxfan, so u know to code programs in cobol , cud u pls suggest me some ebooks, or tutorials on cobol cause i'm also learnin COBOL, for AS 400 and mainframes.
|
 That was many years ago! I don't remember anything in COBOL now. Completely out of touch
|
|
|
28-07-2006, 10:19 PM
|
#12 (permalink)
|
|
Beware of the innocent
Join Date: Dec 2005
Posts: 1,024
|
Re: a small c problem
|
|
|
28-07-2006, 10:54 PM
|
#13 (permalink)
|
|
In The Zone
Join Date: Jul 2005
Posts: 324
|
Re: a small c problem
Quote:
|
Originally Posted by aniishvara@gmail.com
no ...u r not right!!! cos i have to print it as eleven for 11 , and not split the numbers as one one or for that matter 18 as eight-een
any numbershould be printed as we read it
like eighteen, 25 as twenty five itself and not like two-five as stated by u!!!
c this is the problem..and i do not want to use some stupid switch case or some else if ladders to print it appropriately!!!
|
Create a dictionary in an array, and u don't have to use 'case' or 'else if ' ladders.
|
|
|
29-07-2006, 11:13 AM
|
#14 (permalink)
|
|
Right Off the Assembly Line
Join Date: May 2006
Posts: 30
|
Re: a small c problem
Quote:
|
Originally Posted by puja399
Create a dictionary in an array, and u don't have to use 'case' or 'else if ' ladders.
|
wat is a dictionary in an array???
and how wud u create a dicitonary in an array???
|
|
|
29-07-2006, 01:07 PM
|
#15 (permalink)
|
|
I see right through you.
Join Date: Sep 2005
Location: Chennai
Posts: 597
|
Re: a small c problem
Methinks puja399 is confused, dictionaries are native python...or so I believe.
__________________
I didn't make the world, I only try to live in it.
http://lucentbeing.com
-- Sykora --
|
|
|
29-07-2006, 05:22 PM
|
#16 (permalink)
|
|
Beware of the innocent
Join Date: Dec 2005
Posts: 1,024
|
Re: a small c problem
c or c++?? @puja??
|
|
|
29-07-2006, 10:07 PM
|
#17 (permalink)
|
|
Human Spambot
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
|
Re: a small c problem
I think puja means that you use dictionary classes/templates to work with... Something such as http://www.codeguru.com/cpp/cpp/cpp_...icle.php/c869/ indicates... Creating maps will reduce the work in if-then-else clauses...
Arun
|
|
|
29-07-2006, 10:57 PM
|
#18 (permalink)
|
|
God of Mistakes...
Join Date: Dec 2005
Location: Pune, Maharashtra
Posts: 1,923
|
Re: a small c problem
I think he should first check the number of Digits in given input.
ex. 10,286. Here it is 5. Hence the output string must contain "Thousand".
Then it is easy to write the code. Bcoz TEN is same for Lacks, Hundreds & TEN also.
Isn't it?
|
|
|
29-07-2006, 11:14 PM
|
#19 (permalink)
|
|
In The Zone
Join Date: Jul 2005
Posts: 324
|
Re: a small c problem
Quote:
|
Originally Posted by sakumar79
|
Exactly so, however, u can implement a simple map in C using a 2D array.
|
|
|
30-07-2006, 03:56 AM
|
#20 (permalink)
|
|
In The Zone
Join Date: Jan 2005
Location: Somewhere in motherboard
Posts: 439
|
Re: a small c problem
Why don't you start a new thread for your problem? Don't hijack threads
-tuxfan
i have a problem in c++
#include<iostream.h>
class outer { int a;
class inner {
int b;
public:
int c:
void prn(void)
{
cout<<endl<<"inner :: prn()"<<endl;
cout<<b<<c<<endl;
}
inner()
{
b = 5;
c = 10;
}
};
inner ob1;
public:
inner ob2;
void second(void)
{
cout<<endl<<"Outer::second()"<<endl;
cout<<ob2.c<<endl;
cout<<"A = "<<a<<endl;
ob1.prn();
}
outer()
{
a = 25;
}
};
void main()
{
outer ab;
ab.second();
ab.ob2.prn();
}
the errors are
--------------------Configuration: example of nested class - Win32 Debug--------------------
Compiling...
example of nested class.cpp
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(7) : error C2062: type 'void' unexpected
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp( 8 ) : error C2334: unexpected token(s) preceding '{'; skipping apparent function body
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(39) : error C2039: 'prn' : is not a member of 'inner'
D:\Documents and Settings\Sudipta\school\c++\example of nested class.cpp(3) : see declaration of 'inner'
Error executing cl.exe.
example of nested class.obj - 3 error(s), 0 warning(s)
__________________
Game Khelwanu Magazine Padhwanu Majjani Life
http://sudiptatech.blogspot.com/
http://sudiptamondal.blogspot.com/
Last edited by tuxfan; 30-07-2006 at 10:56 AM.
|
|
|
30-07-2006, 06:52 AM
|
#21 (permalink)
|
|
Human Spambot
Join Date: Nov 2004
Location: Madurai
Posts: 2,349
|
Re: a small c problem
I think in line 6, the end of the statement you have given : instead of ;. Change it and check.
Arun
|
|
|
30-07-2006, 07:30 AM
|
#22 (permalink)
|
|
In The Zone
Join Date: Jan 2005
Location: Somewhere in motherboard
Posts: 439
|
Re: a small c problem
thanks a lot but this was a very silly mistake
__________________
Game Khelwanu Magazine Padhwanu Majjani Life
http://sudiptatech.blogspot.com/
http://sudiptamondal.blogspot.com/
|
|
|
30-07-2006, 11:09 AM
|
#23 (permalink)
|
|
Human Spambot
Join Date: Feb 2004
Location: Mumbai
Posts: 2,653
|
Re: a small c problem
Quote:
|
Originally Posted by shirish_nagar
I think he should first check the number of Digits in given input.
ex. 10,286. Here it is 5. Hence the output string must contain "Thousand".
Then it is easy to write the code. Bcoz TEN is same for Lacks, Hundreds & TEN also.
Isn't it?
|
I think he will be better off converting the string to numbers first! So that if someone plays a mischief by entering say a string like "A5463" then the program doesn't process it at all.
Secondly, here're 2 hints!
Use the mod operator % 
Use arrays with the strings "twenty" "thirty", etc.
Use some more arrays and variable of course. I guess these hints are enough
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|