hello

im trying to fill an array of size 16 A-P forward and backward but im having a hard time filling the array with A-P. heres what i have so far.


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

int main()
{

	int arr[16];
	char mych='A';
	int i;

	for(i=0; i<16; ++i)
		arr[i]=mych;

	cout<<"\n";

	for(i=0; i<16; ++i)
		cout << setw(4)<<arr[i];

	cout << "\n\n";

	for(i=15; i>=0; --i)
		cout << setw(4)<<arr[i];

	cout<<"\n\n";
	system("pause");
	return 0;
}
Last edited on
You're storing the same character every time. Seems to me like you want to modify the value of the character each time through the loop.

If you want to store P to A, then you probably want another loop that starts with P and decrements the value.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
http://v2.cplusplus.com/articles/jEywvCM9/
It makes it easier to read your code and it also makes it easier to respond to your post.
Topic archived. No new replies allowed.