Make this operation reoccuring.

Hi,

Im a new student at c++ and have began learning from the book "C++ Programming From Problem Analysis to Program Design Edition 5 by - D.S Malik"

In the book chapter 5 asks a question to make this program repeat as many times as the person desires.

This program turns a string into numbers using the letters on a mobile phone like abc is 1, def is 2 etc..

I have it working fine but want to ask the user after the first run through, if they would like to process another string..

I have a problem with the cin >> letter; statement, it doesn't clear the input from the first runthrough and i can't get it to clear to run again when i try..

Here is the code for the first run through so how do i get the program to process a 2nd time and clearing the first input?

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
123
124
125
126
127
128
129
130
131
/*
Author: Jeffrey Holmes
Date: 
Description: 
*/
#include <iostream>
using namespace std;
#include <conio.h>
#include <iomanip>
#include <stdlib.h>
#include <string>



int main()
{
    system("CLS");
    
    char letter, processagain;
    bool stop = false;
    string line, result, string1 = "";
    int i=0, j=0;
    
    cout << "Program to convert letters to their corresponding telephone digits." << endl;
    
    cout << "Enter a string to convert: ";
    cin >> letter;
    
    while (letter)
    {
      if (i < 7 && letter >='A' && letter <='z' || letter == ' ')
      {
          switch (i)
          {
              case 3:
                   result = result + '-';
              default:
                  line = line + letter;
                  switch (letter)
                  {
                     case ' ':
                          result = result + ' ';
                          i = i - 1;
                          break;
                     case 'A':
                     case 'B':
                     case 'C':
                     case 'a':
                     case 'b':
                     case 'c':
                          result = result + '2';
                          break;
                     case 'D':
                     case 'E':
                     case 'F':
                     case 'd':
                     case 'e':
                     case 'f':
                          result = result + '3';
                          break;
                     case 'G':
                     case 'H':
                     case 'I':
                     case 'g':
                     case 'h':
                     case 'i':
                          result = result + '4';
                          break;
                     case 'J':
                     case 'K':
                     case 'L':
                     case 'j':
                     case 'k':
                     case 'l':
                          result = result + '5';
                          break;
                     case 'M':
                     case 'N':
                     case 'O':
                     case 'm':
                     case 'n':
                     case 'o':
                          result = result + '6';
                          break;
                     case 'P':
                     case 'Q':
                     case 'R':
                     case 'S':
                     case 'p':
                     case 'q':
                     case 'r':
                     case 's':
                          result = result + '7';
                          break;
                     case 'T':
                     case 'U':
                     case 'V':
                     case 't':
                     case 'u':
                     case 'v':
                          result = result + '8';
                          break;
                     case 'W':
                     case 'X':
                     case 'Y':
                     case 'Z':
                     case 'w':
                     case 'x':
                     case 'y':
                     case 'z':
                          result = result + '9';
                     default:
                        break;
                  }
                  cin.get(letter);
                  i = i + 1;
          }
     }
     else
       break;
    } //end while
    cout << line << " = " << result << endl;
       
    cout << "Finished" << endl;
    
    system("PAUSE");
    return 0;
    
}

Topic archived. No new replies allowed.