Do i have to use pointers to transfer values?

Do i have to use pointers to transfer values? from character to input. -> line 13 and 19.
Also how can i output at variable called input from last to the first, can i write input--
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>
using namespace std;

int main()
{
    char character, input;
    int i, it;
    cin >> character;

    if (character == 'c') {
        for( i = 1 ; i <= 9 ; i++ ){
        cin >> character;
        input=character;

        }}

    if (character == 'b'){
    for( it = 9; it > 1 ; it-- ){
        cout << "Variable is " << input << ' ' << it << endl;
        cin >> character;
    }}
return 0;
}
Last edited on
Sorry, can you explain what are you trying to do with that program ?
I don't understand ...
I don't know is this what are you trying to achieve ?

If you want to store data you need to use Arrays, in this case it is char Array, you can google everything about arrays.

Also you don't need to declare "i" and "it" at beginning you can simply do it this way :
1
2
3
4
5
6
for (int i=0; i<9; i++) {

}
for (int it=8; it>=0; it--) {

}


Even if it is not a big deal, just so you know.

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
#include <iostream>
using namespace std;

int main()
{
	char character; 

	char input[9];

	int i; int it;

	cout << "Type c to input characters : ";
	cin >> character;

	if (character == 'c') {
		for (i = 0; i <= 8; i++){
				cin >> character;
				input[i] = character;
		}
	}

	cout << "Type b to write all inputed characters : ";
	cin >> character;

	if (character == 'b'){
		for (it = 8; it >= 0; it--){
			cout << "Variable is " << input[it] << " at " << it << endl;
		}
	}
	system("pause");
	return 0;
}
Last edited on
Topic archived. No new replies allowed.