error: Morse-code

What is wrong with this program. It has probably something to do with this function.

string kodtillmorse(string textin)
{
if (textin == 'A')
kodtillmorse = ".-";
}



CODE:
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
#include <iostream>
#include <string>
#include "iodos.h"

using namespace std;

string kodtillmorse(string textin)
{
	if (textin == 'A')
	kodtillmorse = ".-";
}



int main()
{
	
	dos_console();
// Variabler--------
	char in_mat;
	string Inmatning, kodtillmorse, textout;
	
//------------------
	cout <<"Vad vill du göra?\n(1)Översätta till morse kod?\n(2)Översätta från morse kod till text\nVal: ";
	cin >> in_mat;

	if(in_mat == '1')
	
	{   
		
		cout <<"Skriv in det som ska översättas från text till morsekod: ";
		
		cin >> Inmatning;

		textout = kodtillmorse(Inmatning);


		
	}
	
	else if (in_mat == '2')
	
	{
		cout <<"Skriv in det som ska översättas från morsekod till text: "; 
	}		
}
Can you copy/paste the error your compiler and/or editor is returning? That would help narrow down the problem.
1
2
3
4
5
string kodtillmorse(string textin)
{
	if (textin == 'A')
	kodtillmorse = ".-";
}

you're not returning anything (return ".-";)you're comparing a string to a char (switch textin == 'A' to textin == "A" or use the compare function)
closed account (jLNv0pDG)
Line 21: string Inmatning, kodtillmorse, textout;

kodtillmorse is a function, not a string. You should leave it out:

string Inmatning, textout;
Last edited on
Topic archived. No new replies allowed.