The Program above takes an input from a user, takes out spaces, truncates to 7 letters and turns them into a phone number. (ie: call sam (225-5726). The program works the first time around. The program prompts a user to input a phrase and it outputs the right number. I have it set up to loop as long as the user inputs Y for yes. The problem is the program on the second time through outputs the 1 0 and then starts outputing the right numbers. I need it to figure out how 1 and 0 are being put into my array. I don't have any condition that would put a 1 or a 0 into my array. Thanks in advance to anyone who helps and I am sorry for any bad coding techniques as I am new and this is my first c++ class.Code:// Program: PhoneConvert5_p301
// Programmer: Johnathan Weidman
// Date: 3/1/2010
// Description: This Program takes a stream of charactor values and turns it into numerical data
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main()
{
char ch; // creates a char called ch to hold currint letter to be changed
int phoneNumber[7]; // creates a array called phoneNumber with 8 items.
int count = 0; // this is set up to count how many charecters are inputed
int n = 0;
char answer = 'Y';
// Thefollowoing common out produce the banner
cout << "**********************************" << endl;
cout << "* Programming Assignment V *" << endl;
cout << "* Computer Programming I *" << endl;
cout << "* Author: John Weidman *" << endl;
cout << "* Due Date: Monday, march 1 *" << endl;
cout << "**********************************" << endl;
while ( answer == 'Y')
{
cout << "Please enter a phrase that is atlease seven letter long. \n";
while (count != 7) // checks to see if count is less than 8 and does the following
{
count = count++;// adds 1 to o........
cin.get(ch); // gets a char out of input stream
if (ch == ' ')
{
count = count--;
}
else // checks to make sure that the item is not blank
{
// the following check the letters and change char ch to the corisponding number
switch(ch)
{
case 'a':
case 'A':
case 'b':
case 'B':
case 'c':
case 'C':
ch = 2;
break;
case 'd':
case 'D':
case 'e':
case 'E':
case 'f':
case 'F':
ch = 3;
break;
case 'g':
case 'G':
case 'h':
case 'H':
case 'i':
case 'I':
ch = 4;
break;
case 'j':
case 'J':
case 'k':
case 'K':
case 'l':
case 'L':
ch = 5;
break;
case 'm':
case 'M':
case 'n':
case 'N':
case 'o':
case 'O':
ch = 6;
break;
case 'p':
case 'P':
case 'q':
case 'Q':
case 'r':
case 'R':
case 's':
case 'S':
ch = 7;
break;
case 't':
case 'T':
case 'u':
case 'U':
case 'v':
case 'V':
ch = 8;
break;
case 'w':
case 'W':
case 'x':
case 'X':
case 'y':
case 'Y':
case 'z':
case 'Z':
ch = 9;
break;
}
phoneNumber[n] = ch; // stores the value of ch into an array position n
n = n++; //Accumulates N to change position in aray to store ch
}
}
// outputs array elements and puts dash in phone number
cout << phoneNumber[0] << phoneNumber[1] << phoneNumber[2] << "-" << phoneNumber[3] << phoneNumber[4] << phoneNumber[5] << phoneNumber[6];
// Clears the current input
cin.clear();
cout << "\nwould you like to change a phrase to a number? Enter Y for yes, and N for No\n";
cin >> answer;
// reinitializes count and n to 0
count = 0;
n = 0;
}
system("pause");
return 0;
}