Changing Array Values

Hey guys I have a question.. If I had an array with values such as this:

decade[0] = 1
decade[1] = 2
decade[2] = 4
decade[3] = 8
decade[4] = 16

and I wanted to change these values to a character such as * but I want them to have as many values in them so for instance:

decade[0] = *
decade[1] = **
decade[2] = ****
decade[3] = ********
decade[4] = ****************

how would I do something like that?
Then I think using the std::string type can work.

eg:
1
2
3
4
5
6
7
8
9
string arr[3]={"2","3","1"};
int iTemp;

for(int i=0;i<3;i++){
  iTemp=atoi(arr[i].c_str());
  arr[i].clear();
  for(;iTemp>0;iTemp--)
    arr[i].push_back("*");
}


I think this meets your needs. If you need explations, ask.

Aceix.
Last edited on
if i were you i would set the data in the array into a variable and then
 
if (x==1) {cout << "decade [0] = *"}

and do that for every generation.
(set a value for the asterisks, then measure the value to print the character amount)
but that's just me, and I'm another beginner.
I just think in an array of strings.. e.g
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
#include<iostream>
using std::cout;
using std::endl;

#include<string>
using std::string;


int main(){

string sArray[5];

int limit=1;

for(int index=0;index<5;index++){
        for(int write=1;write<=limit;write++){
                sArray[index]+="*";
        }//end inner loop for
        limit*=2;
}//end outer loop for

for(int index=0;index<5;index++){
        cout<<sArray[index]<<'\n';
}//end loop for

return 0; //indicates successful termination
}//end main 


*
**
****
********
****************
sweet thank you all for the suggestions I got it working with a string..

Thanks you all are very helpful
Topic archived. No new replies allowed.