# Thread: Cheque Printing Program Query

1. ## Cheque Printing Program Query

Hello, I'm quite new to c++ programming and I'm doing a module in it for uni and there is a question I have to complete and I'm at my wits end trying to figure it out, so here goes,

I have to write a cheque printing program that will read in a number and will produce the textual equivalent and I have to do it from 0-999.

So far I have got up to 20 by writing code like this...

Code:
```void units (int u);

cout <<"Please Enter a Number: ";
cin >> n;

{
if (n==0)
{
cout <<"Zero\n";
}```
and all has been working fine but I need to be able to go up to 999 without having up to 999 of that code for each number, so I've been trying to link numbers up for example if 35 is entered it would link the text 'thirty and 'five', but i'm having no luck.

If anyone could give me some advice on how to go about it, I would greatly appreciate it,

Thank you,

Karla xXx

2. I get the feeling you didn't search the boards before asking that question.

3. sorry, I am very new to this type of programming and programming in general, so on the posts I have been looking at have confused me, and i just thought writing my specific problem out i may get a reply that would help me and I could understand.

4. Code:
```//works up to 99
void printTo99(int num)
{
switch(num/10)
{
case 0:
if(num)
printDigit();
else
printf("zero");
break;

case 1:
printTeen();
break;

case 2:
cout<<"twenty";
printDigit();
break;

case 3:
cout<<"thirty";
printDigit();
break;
//continued

}
}```
Where printDigit() prints values 0-9, except 0 and printTeen prints values 10-19. These could actually be combined into one function.

Using simmilar meathods you create a function to print values over 100,

5. Try this:
Code:
```#include <iostream>

char numbers[][10]={"zero","one","two","three","four","five","six","seven","eight","nine"};
char numbers2[][10]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eightteen","nineteen"};
char numbers3[][10]={"","","twenty","thirty","forty","fifty","sixty","seventy","eighty","ninety"};
void units(int u);

int main(){
units(983);
std::cin.ignore(std::numeric_limits<std::streamsize>::max(),'\n');
}

void units(int u){
if(u==0){
std::cout<<numbers[0];
return;
}
int nums[3]={0,0,0};
bool plusand=false;
nums[0]=(u/100)%10;
nums[1]=(u/10)%10;
nums[2]=u%10;
for(int x=0;x<3;x++){
if(nums[x]>0){
if(plusand){
std::cout<<"and ";
plusand=false;
}
if(x==0){
std::cout<<numbers[nums[0]]<<" hundred ";
plusand=true;
}
else if(x==1){
if(nums[1]==1){
std::cout<<numbers2[nums[2]];
break;
}
else{
std::cout<<numbers3[nums[1]]<<" ";
}
}
else{
std::cout<<numbers[nums[2]];
}
}
}
return;
}```

6. Maybe if you pick one of the solutions already provided and ask for clarification? To be honest, I can't think of a simpler solution than some of the ones that have already been posted by either myself or others.

7. Try my code.
And if you get any errors, you should post your code, because otherwise we don't know what you have in your code.

8. thank you for all your replys, have tried your code and there are some errors that i have not seen before.
At the moment im only on the basics of c++, and theres quite alot in the code I haven't learnt yet, so i'm still a little confused on what the code is actually doing, is there a different way for a beginner to write a similar program?

sorry if my questions have obvious answers but i've only been learning c++ really for about 4-5weeks, thanks again. Karla

9. What errors did you get?

10. '::numeric_limits' undeclared (first use here)

parse error before >

implicit declaration of function 'int max()'

parse error before ')'

11. Replace that line with something like this:
Code:
`	std::cin.ignore(10000,'\n');`

12. ah ha it works! lol thank you :-)

13. Code:
```#include <iostream>
#include <string>
using namespace std;

void main (int n)

{

void units (int u);

cout <<"Please Enter a Number: ";
cin >> n;

{
if (n==0)
{
cout <<"Zero\n";
}
if (n==1)
{
cout <<"One\n";
}
if (n==2)
{
cout <<"Two\n";
}
if (n==3)
{
cout <<"Three\n";
}
if (n==4)
{
cout <<"Four\n";
}
if (n==5)
{
cout <<"Five\n";
}
if (n==6)
{
cout <<"Six\n";
}
if (n==7)
{
cout <<"Seven\n";
}
if (n==8)
{
cout <<"Eight\n";
}
if (n==9)
{
cout <<"Nine\n";
}

void tens (int t);

if (n==10)
{
cout <<"Ten\n";
}
if (n==11)
{
cout <<"Eleven\n";
}
if (n==12)
{
cout <<"Twelve\n";
}
if (n==13)
{
cout <<"Thirteen\n";
}
if (n==14)
{
cout <<"Fourteen\n";
}
if (n==15)
{
cout <<"Fifteen\n";
}
if (n==16)
{
cout <<"Sixteen\n";
}
if (n==17)
{
cout <<"Seventeen\n";
}
if (n==18)
{
cout <<"Eighteen\n";
}
if (n==19)
{
cout <<"Nineteen\n";
}

}
}```
This was the code I had before, is there a way to make a program like you posted in that way?
or does there need to variables like 'ten' 'twenty' etc? as alot of the stuff in your program I haven't come across yet, the furthest I have got up to in c++ is the switch statement & loops.

14. Yeah but as you can see I am using those variables I declared as global variables several times. So it would be a terrible waste of time and space.

15. ah okay, thank you