How is my logic wrong for array use?

SO I am trying to break a 3 digit number up into 3 seprate pieces and having them coming out as a string with the use of an array. However I keep getting "undeclared identifier" for my count10[],count1[],and count100[]...why? thanks for reading.


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

#include <iostream>
#include <string>
using namespace std;

string numberToStringOnes(int onesDig)
{ 

static string count1[]{"ZerO","one","two","three","four","five","six","seven","eight","nine","ten",
"eleven","tweleve","thirteen","fourteen","fithteen","sixteen","eighteen","nineteen" };
return count1[onesDig];
}

string numberToStringTens(int tensDig)
{
string count10[] = {"","twenty","thirty","forty","fifty",
"sixty","seventy","eighty","ninety"};
return count10[tensDig];
}

static string numberToString(int hundredDig)
{
static string count100[]{"","hundred","thousands","millions","billions"};
return count100[hundredDig];
}

static string writtenAmountStr(int number)
{	

string digit;
int onesDig, tensDig, hundredDig;

onesDig = number % 10;
tensDig = ((number / 10) % 10);
hundredDig = number / 100;
digit = count100[hundredDig],count10[tensDig],count1[onesDig];
return digit;
}	




int main()
{
//int num=132;
double number;
cout << "enter a 3 digit number : " ;
cin >> number;
cout << 132%10<< endl;
cout << 132/10 << endl;
cout << 13%10 << endl;
cout << 13/10 << endl;
cout << "below is the function example of writtenAmountStr" << endl;
cout << number << endl;

cout << "code gets here" << endl;
cout << writtenAmountStr(number) << endl;
}
You declare count1, count10 and count100 as local variables in functions. Within writtenAmountStr(), there are no variables with those names.
Topic archived. No new replies allowed.