1. ## String Program

hello Everybody,
here in this program. we are getting the values for the corresponding characters. eg., VIJAY = 61111 and the total is 10. After that i have to print the array value....( that is similiar to fibonacci series) like., 6 1 1 1 1 = 7 2 2 2 = 9 4 4= 13 8 =4 11 = 5 2 = 7. the ouput shld be a single value. Here i cant get the desired array value......... plz help me

Code:
```#include<iostream.h>
#include<conio.h>
int main()
{
enum Days{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z};

//Days te;
int sum=0,arr[26];
char name[20];
int aa;
clrscr();
cin>>name;
for(int ia=0;name[ia]!='\0';++ia)
{

//      cout<<name[ia]<<'\t';

if(name[ia]== 'A' || name[ia] == 'I'|| name[ia] == 'J'|| name[ia] == 'Q'|| name[ia] == 'Y')
{
aa= 1;
}
else if(name[ia]=='B' || name[ia]=='K' || name[ia]=='R')
{
aa=2;
}
else if(name[ia]=='C' ||name[ia]=='G'|| name[ia]=='L'||name[ia]=='S')
{
aa=3;
}
else if(name[ia]=='D' ||name[ia]=='M'|| name[ia]=='T')
{
aa=4;
}
else if(name[ia]=='E' ||name[ia]=='X'|| name[ia]=='H'||name[ia]=='N')
{
aa=5;
}
else if(name[ia]=='U' ||name[ia]=='V'|| name[ia]=='W')
{
aa=6;
}
else if(name[ia]=='O' ||name[ia]=='Z')
{
aa=7;
}
else if(name[ia]=='F' ||name[ia]=='P')
{
aa=8;
}

sum = sum+aa;
arr[ia]=aa;
cout<<arr[ia]<<" ";

for(int i=0;arr[i]!='\0';i++)
{
arr[ia]=arr[ia]+arr[ia+1];

cout<<"\n\t array value : "<<arr[ia]<<endl;
}

}
cout<<"Total sum is:"<<sum;
getch();
return 0;
}```

2. Please post what you understand to be the problem.

3. VIBC = 6 1 2 3

Calculatioc: [ 6+1=7
1+2=3
2+3=5 ]

7 3 5

calculation: [ 7+3=10
3+5=8 ]

108

calculation: [ 1+0=1
0+8=8]

18

calculation: [ 1+8=9]

This should the output sir....

4. VIBC = 6 1 2 3

Calculatioc: [ 6+1=7
1+2=3
2+3=5 ]

7 3 5

calculation: [ 7+3=10
3+5=8 ]

108

calculation: [ 1+0=1
0+8=8]

18

calculation: [ 1+8=9]

This should the output sir....

5. You'll need to work with strings for the most of your program. For instance,
Code:
```string aa = "" ;
.
.
.
if(name[ia]== 'A' || name[ia] == 'I'|| name[ia] == 'J'|| name[ia] == 'Q'|| name[ia] == 'Y')
{
aa += "1" ;```
and so on.

Then, after you have processed your letters, your next loop will then take the first character in aa, make it an int, and then tale the second character in aa, make it an int, and add the two. Take the result, convert back to a string, and store it in a new string. Continue for each letter in aa.

That's basically it - I've let out several details.

6. Also, you need to decide if you are writing in C or C++. My example uses a C++ construct.

I have used C++.... Can some help me in this coding.

8. Code:
```#include<iostream>
using namespace std;

int main()
{
int sum=0, arr[26];
string name;
int aa, ia, i, remaining;
cin>>name;
for(ia=0; ia<name.size(); ++ia)
{
if(name[ia] == 'A' || name[ia] == 'I' || name[ia] == 'J'|| name[ia] == 'Q'|| name[ia] == 'Y')
aa= 1;
else if(name[ia]=='B' || name[ia]=='K' || name[ia]=='R')
aa=2;
else if(name[ia]=='C' ||name[ia]=='G'|| name[ia]=='L'||name[ia]=='S')
aa=3;
else if(name[ia]=='D' ||name[ia]=='M'|| name[ia]=='T')
aa=4;
else if(name[ia]=='E' ||name[ia]=='X'|| name[ia]=='H'||name[ia]=='N')
aa=5;
else if(name[ia]=='U' ||name[ia]=='V'|| name[ia]=='W')
aa=6;
else if(name[ia]=='O' ||name[ia]=='Z')
aa=7;
else if(name[ia]=='F' ||name[ia]=='P')
aa=8;
sum += aa;
arr[ia] = aa;
cout<< aa <<" ";
}
cout << endl;
arr[ia] = 0; //set one more element as the terminating element
for(int j=0; j<name.size(); ++j)
{
for(i=0; arr[i+1] != 0; ++i) {
cout << arr[i] << "+" << arr[i+1] << "=";
arr[i] += arr[i+1];
cout << arr[i] << endl;
}
if (i) arr[i] = 0;
remaining--;
}
cout<<"Total sum is:"<<sum << endl;
cout<<"Special Value is:"<<arr[0];
return 0;
}```
Something like that. I don't know if I have the time to test it. Some bounds in the for-loops might not be correct. What I changed is this:
1) You read the letters of the string name and save them in the int array arr. First job done. You have also calculated the sum
2) You do your special calculations. You do total name.size() calculations (not sure, just saw it from your example). Each time you do calculations until the last number (which is set to 0).

Check out the code, even if it doesn't work/compile and post what you think...

EDIT:
Just to point out some errors. Why do you check arr with '\0'? You haven't set any element of arr as '\0' nor have you initialized arr[] to '\0'. So the check won't work
You read one character, set the value to aa, copy it to arr[ia]. Ok. But then you do a loop that has ia+1, which you haven't read yet. You have to do it in two steps, as in my code. Not with an inner loop.
You can use char arr, but learn to use string in C++. So name can be string.
EDIT2:
Fixed. Almost works.
EDIT3:
Didn't pay attention about what happens when the result is >9. Sorry. It seems to need more work...

9. arr[ia]
what if the string is longer than 26 characters?

also
#include <string>
is missing

10. Yeah, you should add a check for input being more than 26 characters.
The best solution I can think is to check if the result is > 9. If it is you will have to separate the number with /10 and &#37;10 and store the two digits in arr[i] kai arr[i+1] after you shift the rest of the numbers in arr. You have to check how many times you shift and adjust teh arr[i] = 0 accordingly so it nullifies the last element. And you are done. It is not hard. Just make a separate function int shift(char *array) that shifts the elements of an array and returns the number it shifted.

11. I got it in this way ...

Code:
```#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
enum Days{A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z};
string lineIn;
vector<int> iVec;
int  aa;

cout.width(6);
cout << "Please enter  a string :";
cin  >> lineIn;
cout << lineIn << endl;

for (int ix = 0; lineIn[ix] != '\0'; ix++) {
switch (lineIn[ix]) {
case 'A': case 'I': case 'J': case 'Q': case 'Y': aa = 1; break;
case 'B': case 'K': case 'R'					: aa = 2; break;
case 'C': case 'G': case 'L': case 'S'			: aa = 3; break;
case 'D': case 'M': case 'T'					: aa = 4; break;
case 'E': case 'X': case 'H': case 'N'			: aa = 5; break;
case 'U': case 'V': case 'W'					: aa = 6; break;
case 'O': case 'Z'								: aa = 7; break;
case 'F': case 'P'								: aa = 8; break;
default											: aa = 0;
}
iVec.push_back (aa);
cout << iVec.back () << " ";
}
cout << endl;

while (iVec.size() > 1) {
for (unsigned i = 0; i < iVec.size(); i++) {

if (i < iVec.size() - 1) {
iVec[i] += iVec[i + 1];
cout.width(2); cout << iVec[i] - iVec[i + 1] << " + ";
cout.width(2); cout << iVec[i + 1] << " = ";
cout.width(2); cout << iVec[i] << endl;
}
}
iVec.pop_back();
}
cout << "Total sum is: " << iVec.front() << endl;

return 0;
}```

12. lineIn[ix] != '\0'

who said that c++ string is nul-terminated?