Conversion problem

I am having trouble converting the numbers into its English version for example $723.63 to Seven hundred and twenty three dollars and sixty three cents.
Also my cin getline seem to be messed up when before they worked perfectly.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;

string hundreds(int);
string first(int);
string second(int);
string cents(int,int);
string getWholeNum(int);

int main(int argc, char** argv) {
    //Declare variables
    string Name;
    string Date;
    float n;
    string holder;
    
    cout<<"Input the date: "<<endl;
    cin>>Date;
    cout<<"Input the name: ";
    cin>>Name;
    cin.ignore();
    getline(cin,Name);
    cout<<"Input the amount in usd $";
    cin>>n;
    cout<<"Input the name of the holder: ";
    cin>>holder;
    getline(cin,holder);
    
    //123.55
    int d=n;//123
    int c=(n-d)*100;//.55
   
   
    
    
    return 0;
}
string getWholeNum(int n){
   int f=(n%10);

    string whole;
}

string hundreds(int a){
  if(a==100){return "One Hundred and";}
  if(a==200){return "Two Hundred and";}
  if(a==300){return "Three Hundred and";}
  if(a==400){return "Four Hundred and";}
  if(a==500){return "Five Hundred and";}
  if(a==600){return "Six Hundred and";}
  if(a==700){return "Seven Hundred and";}
  if(a==800){return "Eight Hundred and";}
  if(a==900){return "Nine Hundred and";}
}
string first(int a){
  if(a==0){return "";}
  if(a==1){return "ten";}
  if(a==2){return "twenty";}
  if(a==3){return "thirty";}
  if(a==4){return "forty";}
  if(a==5){return "fifty";}
  if(a==6){return "sixty";}
  if(a==7){return "seventy";}
  if(a==8){return "eighty";}
  if(a==9){return "ninety";}
}
string second(int a){
  if(a==0){return "";}
  if(a==1){return "one";}
  if(a==2){return "two";}
  if(a==3){return "three";}
  if(a==4){return "four";}
  if(a==5){return "five";}
  if(a==6){return "six";}
  if(a==7){return "seven";}
  if(a==8){return "eight";}
  if(a==9){return "nine";}
}
string cents(int &n,int){
    int d=n;
    
    cout<<" cents";
}

Last edited on
Code tags would make this much easier to read and comment on.
http://www.cplusplus.com/articles/jEywvCM9/
Last edited on
Thank you for showing me i have been wanting to learn that. Now any help would be appreciated.
I took out some of your code that may not have been working but I didn't need for this example. You'll have to put it back in or just add my example to your program.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;

string hundreds(int);
string first(int);
string second(int);
string cents(int,int);
string getWholeNum(int);

int main(int argc, char** argv) 
{
    //Declare variables
    string Name;
    string Date;
    double n;
    int y;
    string holder;
    
    cout<<"Input the amount in usd $";
    cin>>n;

// Example below  
// Pass the values in the cout examples below to your functions.
cout << n << endl; // The number
y=n;
cout << y << endl;// The number without cents

cout << y %10<< endl; // Ones

y=y/10;
cout << y %10<< endl; // Tens

y=y/10;
cout << y %10<< endl; // Hundreads

y=y/10;
cout << y %10<< endl; // Thousands

    return 0;
}

string getWholeNum(int n)
	{
	   int f=(n%10);
	   string whole;
	}

string hundreds(int a)
	{
	  if(a==100){return "One Hundred and";}
	  if(a==200){return "Two Hundred and";}
	  if(a==300){return "Three Hundred and";}
	  if(a==400){return "Four Hundred and";}
	  if(a==500){return "Five Hundred and";}
	  if(a==600){return "Six Hundred and";}
	  if(a==700){return "Seven Hundred and";}
	  if(a==800){return "Eight Hundred and";}
	  if(a==900){return "Nine Hundred and";}
	}

string first(int a)
	{
	  if(a==0){return "";}
	  if(a==1){return "ten";}
	  if(a==2){return "twenty";}
	  if(a==3){return "thirty";}
	  if(a==4){return "forty";}
	  if(a==5){return "fifty";}
	  if(a==6){return "sixty";}
	  if(a==7){return "seventy";}
	  if(a==8){return "eighty";}
	  if(a==9){return "ninety";}
	}

string second(int a)
	{
	  if(a==0){return "";}
	  if(a==1){return "one";}
	  if(a==2){return "two";}
	  if(a==3){return "three";}
	  if(a==4){return "four";}
	  if(a==5){return "five";}
	  if(a==6){return "six";}
	  if(a==7){return "seven";}
	  if(a==8){return "eight";}
	  if(a==9){return "nine";}
	}

string cents(int &n,int)
	{
	    int d=n;
	    cout<<" cents";
	}
I typed 500 and it outputted -
500
500
0
0
5
0

I am unsure why, shouldn't it output the wording and those numbers
Last edited on
I'm not writing it for you just showing you how to get the individual numbers.

The last number 0 after the 5 is because there is no thousands in 500, so you might want to include if statements
Last edited on
I know just thats my problem i dont know how to input it into the functions and retrieve it.
Sorry I thought that was the easy part.

Here's another example. hope it helps.

PS, it only works if #1 is in the ones position.... You'll have to add the rest.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <cstdlib>
#include <iostream>
#include <cstring>
using namespace std;

string hundreds(int);
string first(int);
string second(int);
string cents(int,int);
string getWholeNum(int);

void ones (int a)
	{
	if (a%10==1)
		{
		cout << a%10 << ",one"<< endl;
		}
	}

int main(int argc, char** argv) 
{
    //Declare variables
    string Name;
    string Date;
    double n;
    int y;
    string holder;
    
    cout<<"Input the amount in usd $";
    cin>>n;


y=n;
ones (y);

    return 0;
}
Topic archived. No new replies allowed.