how can i solve this problem

Write your question here.
how do you write program to convert numbers to string in c++

#include<iostream>
using namespace std;

class csh1{
public:

int integer[9];
int integers;
int number(){

for( int c=0;c<=9;c++){
cin>>integers;
if(integer==0){
cout<<"zero"<<endl;
}
if(integer==1){
cout<<"one"<<endl;
}
if(integer==2){
cout<<"two"<<endl;
}
if(integer==3){
cout<<"three"<<endl;
}
if(integer==4){
cout<<"four"<<endl;
}
if(integer==5){
cout<<"five"<<endl;
}
if(integer==6){
cout<<"six"<<endl;
}
if(integer==7){
cout<<"seven"<<endl;
}
if(integer==8){
cout<<"eight"<<endl;
}
if(integer==9){
cout<<"nine"<<endl;
}
}
}
};


int main(){
csh1 convert;
convert.words;
convert.integers;
return 0;
}
Post the code in code tags.
What is the problem? I mean apart from the class csh1 doesn't seem to have member "words" and the member "integers" is declared as a single int
Did you even try to compile this? As codewalker said, convert.words doesn't exist. convert.integers; does nothing.

Did you mean to call your function?
 
  convert.number();  //  This is a function call 


PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
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
#include<iostream>

using namespace std;

class csh1{
  public:

  void number(){//why not make this function void, since you're not returning anything

  /*int integer[9];take away this array, it does nothing, just waist dataspace*/

 int integers; /*if you see in integers, then compare integers, otherwise you're comparing random numbers in a uninitialized array*/

  for( int c=0;c<=9;c++){
    cin>>integers;

    if(integers==0){
    cout<<"zero"<<endl;
    }

    else if(integers==1){
    cout<<"one"<<endl;
    }

    else if(integers==2){
    cout<<"two"<<endl;
    }

    else if(integers==3){
    cout<<"three"<<endl;
    }

    else if(integers==4){
    cout<<"four"<<endl;
    }

    else if(integers==5){
    cout<<"five"<<endl;
    }

    else if(integers==6){
    cout<<"six"<<endl;
    }

    else if(integers==7){
    cout<<"seven"<<endl;
    }

    else if(integers==8){
    cout<<"eight"<<endl;
    }
    else if(integers==9){
    cout<<"nine"<<endl;
    }

    else{
    cout << "not a number from 0 to 9" << endl;
    }
                                     }

                               }
};


int main(){

  csh1 convert;

  /*I would say, stay away from classes and objects, until you learn the
  basics, especially using else if instead of if if if...
  convert.words;
  convert.integers;
  also neither words or integers is a function class member of csh1*/

  convert.number(); // this one is, and its what you should call


return 0;
}
Last edited on
I would have used switch statements as well, but you should pace down and learn things one at a time... Read a lot of literature and ask around the forums, but try to build things the right way according to what you've learned and pay attention to detail, and you won't need help... cheers! :)

Oh yeah and learn about indenting! makes our work of helping you solve things a lot easier! most IDE's have commands for indenting just check the help tab, or setting and again cheers! :)
Last edited on
Topic archived. No new replies allowed.