Apaxiaans!! katis problem

I think my program for Apaxiaans on katis is correct mostly. however it's being returned as wrong. I think this is due to it returning each letter in the compacted name on a different line instead of as one word. Any ideas? thanks. I know there's some messy stuff edited out, sorry if it's hard to read.

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
/*
https://open.kattis.com/problems/apaxiaaans
This program is designed to translate the ancient civilization of Apaxia's naming system into a more readable format.
The Apaxiaans apply merit to having the more letters in their name and more if consecutive letters repeat.  So 
this program will compact names into their shortest form with no consecutive repeating letters.

Algorithm
1. create main function
2. declare variables string ApaxiaanName, string compactName, and int nameLength.
3. output prompt asking for Apaxiaan name.
4. allow for Apaxiaan name input
5. set namelength = to the length of string ApaxiaanName using .length to read value
6. create for loop to using increments compacting name until there are no more repeating letters
7. ouput compacted name


*/

#include <iostream>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main() {
	//string ApaxiaanName, compactName;

	//int nameLength;
	//int a = 1;
	{
		string ApaxiaanName; //declares string
		int nameLength; //declares int to store length value

		cout << "Please enter Apaxiaan name you'd like translated: " << endl; //prompts request for Apaxiaan name
		cin >> ApaxiaanName; //allows input of Apaxiaan Name


	//ApaxiaanName = " ";
	//compactName = " ";
		nameLength = ApaxiaanName.length(); // stores value of the length of ApaxiaanName as integer
		char compactName = ' ';
		for (int i = 0; i < nameLength; i++) // sets loop til Apaxiaan name has fewest possible not repeated consectutive letters
		{
			if (ApaxiaanName[i] != compactName)
			{
				compactName = ApaxiaanName[i]; // when the counter for Apaxian[i] 
				cout << ApaxiaanName << " translates to : " << ApaxiaanName[i] << endl; // outputs compacted name 
				// for some reason it's printing each letter on a new line
				//cout << "The name in compacted form is: " << ApaxiaanName[1] << endl;
			}
		}
		cin.ignore(1000); // dont know what this does but my print screen stays with it so it's here.
		cin.get();

		return 0;
	}
}
You are on the right track, but not quite. compactName on line 42 isn't the compacted name for the output. The output needs to be after the loop. Consider this:
1
2
3
4
5
6
7
8
9
10
11
12
13
		string compactName(1, ApaxiaanName[0]);
		// Note that the loop starts with 1 (the first(0) character is alread stored)
		for (int i = 1; i < nameLength; i++) // sets loop til Apaxiaan name has fewest possible not repeated consectutive letters
		{
			if (ApaxiaanName[i] != ApaxiaanName[i-1]) // Compare with previous
			{
				compactName += ApaxiaanName[i]; // when the counter for Apaxian[i] 
				//cout << ApaxiaanName << " translates to : " << ApaxiaanName[i] << endl; // outputs compacted name 
				// for some reason it's printing each letter on a new line
				//cout << "The name in compacted form is: " << ApaxiaanName[1] << endl;
			}
		}
		cout << ApaxiaanName << " translates to : " << compactName << endl; // outputs compacted name 
Fort the constructor on line 1, see this:

http://www.cplusplus.com/reference/string/string/string/
Topic archived. No new replies allowed.