troubles with arrays.

hi! so i have an assignment which consist of a bunch of functions. One of the functions is used to read characters inputted by the user and place them into an array, it also has to initialize the parameter current to zero.This is what I have,and i wanted to make sure I was doing it correctly. thank you.

1
2
3
4
5
6
7
8
9
10
void input (char letters[11], int& current)
{
int entered;

current = 0;
cout << "Enter 11 non-blank characters: ";
for (entered = 0; entered < current; entered++)
current = current + letters[entered];
cin >> letters[entered];
}
1
2
3
current = 0;
cout << "Enter 11 non-blank characters: ";
for (entered = 0; entered < current; entered++)


current = 0; and entered = 0;

The loop wont run.
when I call the function into main I can enter numbers, but when I try and use my function to print what I put in, it won't print the word i typed in. so what should i set entered to? I thought the loop had to start at index 0 to go through it.
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
#include <iostream>


using namespace std;
//global declaration space
void input (char letters[11], int& current);
void swap (char letters[11], int current);
void add (char letters[11], int current);
void subtract (char letetrs[11], int current);
void change (char letters[11], int current);
void move (int& current);
void print (char letters [11], int current);


int main()

{//begin main
//declarations for input function.
char ch[11] = {0};
int cur;
//switch
char functionChoice;
//input function
input(ch, cur);
}




    
system("PAUSE");
return 0;   
}//end main

void input (char letters[11], int& current)
{
int entered;

current = 0;
cout << "Enter 11 non-blank characters: ";
for (entered = 0; entered < current; entered++)
current = current + letters[entered];
cin >> letters[entered];
}
Can you explain exactly what you are trying to do, please. I don't really get it from your code.

1
2
for (entered = 0; entered < current; entered++)
current = current + letters[entered];


letters[ entered ] actually doesn't have anything set in there yet( garbage value ), yet you're adding it to current.
for that function in particular I need to prompt the user for the size characters (which is 11 characters), read the characters and place them in the array, i also need to initialize the variable current to 0.
To use this loop:
for (entered = 0; entered < current; entered++)

current would have to be greater than 0; i.e. 11 ( the size of the array ).
Topic archived. No new replies allowed.