|
A question is given as below:
A whole-sales company requires a program that will help to print cheque like the one below:
Write a C++ program to perform the following:
- Input fields: NAME, IC NUMBER, AMOUNT
- Output : produce the cheque as above with name, ic number, amount and amount in words
example:
amount amount in words
-----------------------------------------
40.00 Forty only
123.00 One Hundred and Twenty Three only
2323.00 Two Thousands Three Hundred and Twenty Three only
Then, my output is as below but occur an error (someone tells me where got error):
#include <iostream.h>
#include <string.h>
char *GetValue(char);
char *GetValue2(char);
char *GetValue3(char);
void main()
{
char Name[80], IC[14], Amount[9];
int i, n;
cout << "Please write your name: ";
cin >> Name;
cout << "Your ic number: ";
cin >> IC;
cout << "The amount of money: RM";
cin >> Amount;
for(i = 0; i <= 79; i++)
cout << "*";
cout << "Shanghai Bank Berhad, Kuala Lumpur, 55210"
<< endl << endl;
cout << "Payee: " << Name << "\t\t\tRM" << Amount <<
endl;
cout << "Amount: ";
i = 0;
n = strlen(Amount);
if(n == 9)
{
cout << GetValue(Amount[i]) << "Hundred ";
n--;
i++;
}
if(n == 8)
{
if(Amount[i] == 49)
{
i++;
cout << GetValue3(Amount[i]) << "Million ";
n -= 2;
i++;
}
else
{
cout << GetValue2(Amount[i]);
n--;
i++;
}
}
if(n == 7)
{
cout << GetValue(Amount[i]) << "Million ";
n--;
i++;
}
if(n == 6)
{
cout << GetValue(Amount[i]) << "Hundred ";
n--;
i++;
}
if(n == 5)
{
if(Amount[i] == 49)
{
i++;
cout << GetValue3(Amount[i]) << "Thousand ";
n -= 2;
i++;
}
else
{
cout << GetValue2(Amount[i]);
n--;
i++;
}
}
if(n == 4)
{
cout << GetValue(Amount[i]) << "Thousand ";
n--;
i++;
}
if(n == 3)
{
cout << GetValue(Amount[i]) << "Hundred ";
n--;
i++;
}
if(n == 2)
{
if(Amount[i] == 49)
{
i++;
cout << GetValue3(Amount[i]);
n -= 2;
i++;
}
else
{
cout << GetValue2(Amount[i]);
n--;
i++;
}
}
if(n == 1)
{
cout << GetValue(Amount[i]);
}
cout << "Dollars" << endl;
for(i = 0; i <= 79; i++)
cout << "*";
}
char *GetValue(char Value)
{
switch(Value)
{
case 48: return "";
case 49: return "One ";
case 50: return "Two ";
case 51: return "Three ";
case 52: return "Four ";
case 53: return "Five ";
case 54: return "Six ";
case 55: return "Seven ";
case 56: return "Eight ";
case 57: return "Nine ";
}
}
char *GetValue2(char Value)
{
switch(Value)
{
case 48: return "";
case 50: return "Twenty ";
case 51: return "Thirty ";
case 52: return "Fourty ";
case 53: return "Fivety ";
case 54: return "Sixty ";
case 55: return "Seventy ";
case 56: return "Eighty ";
case 57: return "Ninety ";
}
}
char *GetValue3(char Value)
{
switch(Value)
{
case 48: return "";
case 49: return "Eleven ";
case 50: return "Twelve ";
case 51: return "Thirteen ";
case 52: return "Fourteen ";
case 53: return "Fiveteen ";
case 54: return "Sixteen ";
case 55: return "Seventeen ";
case 56: return "Eighteen ";
case 57: return "Nineteen ";
}
}
|
|
|
|
|
You REALLY have got to read the message when someone answers your post - please correct your post by doing the things suggested...
Peace!
-=- James If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
|
|
|
|
|
while (unapplicable)
read <a href="http://www.codeproject.com/script/comments/forums.asp?msg=1374631&forumid=1647#xx1374631xx" rel="nofollow">this</a>[<a href="http://www.codeproject.com/script/comments/forums.asp?msg=1374631&forumid=1647#xx1374631xx" target="_blank" rel="nofollow" title="New Window">^</a>]
endwhile
ps, as it looks like an homework, semms that you'll have to find your way yourself...
TOXCCT >>> GEII power [toxcct][VisualCalc 2.24][3.0 soon...]
|
|
|
|
|
toxcct wrote: while (unapplicable) read this[^]endwhile
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
dannysoo2020 wrote: occur an error
Ok, but what error?
It happens during compile or when the program is running?
If it is a runtime error you can mark the program flow with markers like:
cout<<descriptionstring;
to know="" the="" value="" of="" some="" variables="" and="" where="" are="" you="" at="" before="" error.
or,="" better,="" use="" break-points="" on="" your="" c++="" editor="" if="" it="" has="" they.
please,="" be="" more="" clear.=""
<p="" style="background-color:'#50D0B0'">Have a nice code day
|
|
|
|
|
|
I'm really trying to help this guy, so I'm trying to understand if he needs some basic tips.
And, of course, trying to use a 'friendly' message!;)
Have a nice code day
|
|
|
|
|
SORRY guys. I'm a newbie in programming, know nothing , this is my 1st assignment to learn about C++. Thx for your help anyway. ;)
|
|
|
|
|
Ooops , forgot to tell you all never mind already, already can run the program with changing the front parts :
#include <iostream>
#include <string>
using namespace std;
Thanks again to all of you, thanks thanks thanks.
Danny
|
|
|
|
|
dannysoo2020 wrote:
A question is given as below:
Yes, but what problem are you having. We know what the assignment is, but you have not indicated the section of code that is troubling you.
See here for clues.
"The greatest good you can do for another is not just to share your riches but to reveal to him his own." - Benjamin Disraeli
|
|
|
|
|
|
|
Yes, of course I meant piss... err piece of code
|
|
|
|
|
Check "Ignore HTML tags in this message (good for code snippets)"! That will display your code better!
|
|
|
|
|
dannysoo2020 wrote: char *GetValue(char);
char *GetValue2(char);
char *GetValue3(char);
I thinkt that this should be:
const char *GetValue(char);
const char *GetValue2(char);
const char *GetValue3(char);
codito ergo sum
|
|
|
|
|
dannysoo2020 wrote: case 57: return "Nineteen ";
It working fine on my computer
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
|
|
|
|
|
Hi!
I had download the source code of mass storage device driver for windows98 from Microsoft websit.And builded it with 98ddk on windows98 system,and then
installed it on win98 system. It can work correctly all the time.
If I suddenly remove the device from pc when copying file from pc to device or from device to pc on win98 system,the blue screen occur,and i have to restart my system.
But if do the same on win2000 or winxp there is no blue screen.
Now i wanna modify the driver source code to avoid the blue screen when suddently remove the device while it is exchanging data with pc on win98 system.
My question is:
1,If my hope has the possibility to come true?
2,If has,then which part of source code of this drive should i have to modify,and what couses the blue screen?
I know that in the source code it just abort all the pipes when device remove sudently but nothing else.
Thanks!
momer
All the blesses we are enjoy are the fruit of labor,toil,study and selt-denail.
|
|
|
|
|
Hi,
Is there any upgradation tool for migrating VC++ 6.0 code to VC++ 2005 code. This project in VC++ 6.0 has ATL and COM components.
Are there complete tutorial for this upgradation.
Is there any tool that upgrades atleast partially?
Any help in this regard is appreciated.
Sugan
Chennai
-- modified at 6:27 Friday 17th February, 2006
|
|
|
|
|
You can try opening it with Visual 2005 studio it will ask for converting teh code from VC++ 6.0 to vc++ 7.0
Cheers
|
|
|
|
|
You can try opening it with Visual 2005 studio it will ask for converting the code from VC++ 6.0 to vc++ 7.0
Cheers
|
|
|
|
|
|
Well thanx for the info.
Hey can you give me a link where i can fnd the diffrence between Vc++.net 2002 and Vc++.net 2005
Cheers
|
|
|
|
|
Hello,
I usually work with microcontrollers in a C/C++ environment, but i need to write a programm to download software in the microcontrollers (through RS232). I want to do this in Visual C++. I allready have written software that downloads the software correctly, but while downloading, my programm hangs. I would like to use multithreading to prevent this.
Whereever I look for help, it appears to be too complicated for a beginner like me. I just want my programm to have 2 threads: 1 for the serial communication and 1 for the GUI.
|
|
|
|
|
u can use CreateThread() function for this. The function creates a new thread.
eg:
CreateThread( 0, 0,(LPTHREAD_START_ROUTINE)ThreadProc, 0, 0, 0 );
When the above function is called, anew thread will be created and it will call the function ThreadProc
The function ThreadProc must be define as
DWORD WINAPI ThreadProc(
LPVOID lpParameter
)
{
// begining of new thread
}
nav
|
|
|
|
|
If you plan on using any CRT functions (C/C++ runtime) like malloc etc, then rather than using CreateThread, you should use _beginthreadex. You need to make sure that you're building a multithreaded app and using the right versions of the runtime libraries. A simple check is
#if !defined(_MT)
#error "Not building correctly"
#endif
since selecting multithreaded runtine libraries will defined _MT as a preprocessor symbol. Of the arguments to _beginthreadex, you are usually best passing 'security' as NULL, stack_size as zero.
If you've never used multiple threads before, then you're in for a treat, since it will involve an element of synchronisation.
Steve S
Developer for hire
|
|
|
|