Strings and Arrays

Hey Guys,
I recently got a problem where I was given a message which had several of the letters repeated several times due to a faulty transmitter. I had to remove the extra letters and get the correct message. No two adjacent letters in the correct message are the same.

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
#include <iostream.h>
#include <string>
using namespace std;


int main()
{
    int a, b, c;
    cin  >> c;
    string Message;
    string CorrectMessage[50];
    cin >> Message;
    int n=0, i=0, j=0, result;
    string let1, let2;
    ///////////////// Making Correct Message
    while(j < c)
    {
            let1 = Message[i];
            let2 = Message[j];
            
          if(let1 == let2)
          {
                  j == j++;
          }
          else
          {
                        CorrectMessage[n] = let1;
                        cout << "let1 : " << let1 << endl;
                        n == n++;
                        i = j;
                        j == j++;
                        cout << "CorrectMessage[n] = " << CorrectMessage[n] << endl;
          }
    }

    cin.get();
    cin.ignore();
    return 0;
}


However in line 27, when I want to put the value of let1 as an element of the CorrectMessage array, it prints out the correct value for let1 (at line 28) but does not set the value for CorrectMessage[n] (at line 32). Can you tell me how I enter the value for an array element from a variable?
Last edited on
Those are different values of n, due to n++ on line 29. By the way, n== does noting in this case.
Just put the cout before the n++.

Also, '==' is the comparison operator, not the assignment operator ('='). Just typing 'n++;' is sufficient to increment it.
Thanks everyone for the help!
iostream shouldn't have the .h
Topic archived. No new replies allowed.