a small c problem

Status
Not open for further replies.
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.
 

Sykora

I see right through you.
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.
 

tuxfan

Technomancer
I am glad you guys didn't give out the code :D 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.
 
OP
aniishvara@gmail.com
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!!!
 

dheeraj_kumar

Legen-wait for it-dary!
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
 
OP
aniishvara@gmail.com
dheeraj_kumar said:
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!!!
 

paul_007

Padawan
tuxfan said:
I am glad you guys didn't give out the code :D 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.
 

sakumar79

Technomancer
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
 

tuxfan

Technomancer
paul_007 said:
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 :(
 

ilugd

Beware of the innocent
@paul
*www.csis.ul.ie/COBOL/
*www.freeprogrammingresources.com/coboltutr.html
*www.programmingtutorials.com/cobol.aspx
 

puja399

In the zone
aniishvara@gmail.com said:
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.
 

sakumar79

Technomancer
I think puja means that you use dictionary classes/templates to work with... Something such as *www.codeguru.com/cpp/cpp/cpp_mfc/collections/article.php/c869/ indicates... Creating maps will reduce the work in if-then-else clauses...

Arun
 

Garbage

God of Mistakes...
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?
 

puja399

In the zone
sakumar79 said:
I think puja means that you use dictionary classes/templates to work with... Something such as *www.codeguru.com/cpp/cpp/cpp_mfc/collections/article.php/c869/ indicates... Creating maps will reduce the work in if-then-else clauses...

Arun

Exactly so, however, u can implement a simple map in C using a 2D array.
 

Official Techie

In the zone
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)
 
Last edited by a moderator:
Status
Not open for further replies.
Top Bottom