function and for loops

I have been trying to get this program to work for a long time please assist me, I have really tried everything i know how to do and can comprehend from google >.<
I am trying to allow the user to enter a number after hitting 'n' that counts the characters next to each of the listed letters I could only get it to work for box[1] on line 108 please help me get it to work on the others.... :/
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <iostream>
#include <iomanip>
#include <string>
#include <stdio.h>
#include <string.h>

using namespace std;

void printWordLengths(char inputa[], char inputb[], char inputc[], char inputd[], char inpute[], char inputf[]);
void printNeighbors(int x);
char path;
int count = 0;

int main(){
	cout << "N[eighbors] W[ords] Q[quit]\n";
	
	
	while( path!='q' || path!='Q'){
		cout << "\nEnter your choice -> ";
	    cin >> path;
		
		if( path=='w' || path=='W'){
		
			char wordt[] = "These";			
			char wordc[] = "classes";			
			char worda[] = "are";			
			char wordr[] = "really,";			
			char wordrr[] = "really";
			char worde[] = "easy!";
			printWordLengths(wordt, wordc, worda, wordr, wordrr, worde);
			//cout << "W works";
			//string words[7] = {"These","classes", "are", "really,", "really", "easy!"};
			//printWordLengths(words);
		}
		if(path=='n' || path=='N')
			
			cout << "n works";
			cout << "Enter the number of letters to show ";
			cin >> count;
			printNeighbors(count);
			
	}
		
		
	
	return 0;
	
	
	}
//cout << "N[eighbors] W[ords] Q[quit]\n";
//cout << "Enter your choice -> ";
//cin >> ;
	void printWordLengths(char inputa[], char inputb[], char inputc[], char inputd[], char inpute[], char inputf[]){
	
		cout << "Word #1 is " << strlen(inputa)<< " characters.\n";
		cout << "Word #2 is " << strlen(inputb)<< " characters.\n";
		cout << "Word #3 is " << strlen(inputc)<< " characters.\n";
		cout << "Word #4 is " << strlen(inputd)<< " characters.\n";
		cout << "Word #5 is " << strlen(inpute)<< " characters.\n";
		cout << "Word #6 is " << strlen(inputf)<< " characters.\n";
	
		return;
	}
void printNeighbors(int x){

	string box [30];
	
	char e = 'e';
	char f = 'f';
	char g = 'g';
	char h = 'h';
	char i = 'i';
	char j = 'j';
	e = e - x;
		f = f - x;
		g = g - x;
			h = i - x;
			i = i - x;
			j = j - x;

	

	for(int i=0; i<x; i++)
		{
			
			box[1] = box[1] + e++;
			box[2] = box[2] + f++;
			//f
			box[3] = box[3] + f++;
			box[4] = box[4] + g++;
			
			box[5] = box[5] + g++;
			box[6] = box[6] + h++;
			
			
			box[7] = box[7] + h++;
			//box[8] = box[8] + i++;
			
			box[9] = box[9] + j++;
			box[10] = box[10] + g++;
			
			box[11] = box[11] + h++;
			box[12] = box[12] + g++;
			
		}


	cout << "The " << x << " neighbors of 'e' are:" << box[1] << " and " << box[2] << endl;
	cout << "The " << x << " neighbors of 'f' are:" << box[3] << " and " << box[4] << endl;
	cout << "The " << x << " neighbors of 'g' are:" << box[5] << " and " << box[6] << endl;
	cout << "The " << x << " neighbors of 'h' are:" << box[7] << " and " << box[8] << endl;
	cout << "The " << x << " neighbors of 'i' are:" << box[9] << " and " << box[10] << endl;
	cout << "The " << x << " neighbors of 'j' are:" << box[11] << " and " << box[12] << endl;
	return;

}
//cin.ignore();
//cin.get();
	
	

//}  
Last edited on
Help please
I don't even get what you're trying to do.
Count the letters next to e-j? That's just the number of occurences of the letters themselves, minus one if the last letter is one of those.
Yes I am trying to count the letters next to e-j based upon a number that a users enters.

for example

Enter a number -> 2
"The 2 neighbors of 'e' are: cd and fg." Please help I can only get it to display a the next letter if they enter 3 i need... "The 2 neighbors of 'e' are: bcd and fgh."

PLEASEHELPME!
Ah. Well, not much will come from it if you're trying to do both directions in the same loop.
Handle the even indices in a second loop.
Topic archived. No new replies allowed.