C++ Question

hi I am supposed to add code and I tried and for some reason the program isnt running!I feel Like I am making a small mistake lol

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
#include <iostream>
#include <string>

using namespace std;


 
void decipher(string &);
int  unmix(string &);
//ADD CODE: Add prototypes for the unmix and decipher functions here

int main()
{
	string code = "K*@*R*S*\037*D*W*D*Q*B*H*R*D* ";
	cout << "Step 0: " << code << endl;

	string unmixed;
	unmixed = unmix(code);
	cout << "Step 1: " << unmixed << endl;

	decipher(unmixed);
	cout << "Step 2: " << unmixed << endl;

	return 0;
}

//Function unmix:
//  Returns a new string containing
//  only the even characters of string s
string unmix(string s)
{
	string ret;
	for (int i = 0; i < s.length(); i++)
	{
		if ("even")//ADD CODE: if i is even

		{
			ret[i];//COMPLETE LINE: add the character at i onto ret
			ret +=i;
		
    }
  }
	return ret;
}

//Function decipher:
//  Implements a Caesar Cipher decoder
//  every character in s will have 1 added on to its value
void decipher(string &s)
{
	for (int i = 0; i < s.length(); i++)//ADD CODE: Write a for loop to that counts i from 0 to the length of string s

	{
		s[i] = s[i]+1;
	}
}
Last edited on
Look at line 9, your function declaration of unmix. You are telling the compiler to pass a std::string reference.
int unmix(string&);

Now look at line 30 where you start your function definition:
string unmix(string s)

You are trying to pass the string by value. The compiler flags this as an error.

Are you wanting to return a string or an int from the function? You need to match the return type.

Fix those errors and try again.
Topic archived. No new replies allowed.