Function Problems

ive been working on a program to encode and decode text, currently just testing but when i run it the functions dont work
when i type e or d it just quits but if i type something else triggering the else block it works fine
does anyone know the probelem?

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
#include<iostream>
#include<cstring>
using namespace std;

int size;
char choice;
string input;
string output;


int main() {
	cout << "Do you want to Encrypt or Decrypt e/d" << endl;
	cin >> choice;
	
	if ( choice == 'e') {
		void encode();
	}
	else if ( choice == 'd') {
		void decode();
	}
	else {
		cout << "Error, please type again" << endl;
		main();
	}
	return 0;
}

void encode() {
	cout << "is working" << endl;
	
}
void decode() {
	cout << " is working " << endl;

}
fixed
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
#include<iostream>
#include<cstring>
using namespace std;

int size;
char choice;
string input;
string output;
void encode(); /// declare functions which you define after main()
void decode(); ///
int main() {
	cout << "Do you want to Encrypt or Decrypt e/d" << endl;
	cin >> choice;
	
	if ( choice == 'e') {
		encode(); /// dont write return type while calling
	}
	else if ( choice == 'd') {
		decode(); ///
	}
	else {
		cout << "Error, please type again" << endl;
		main();
	}
	return 0;
}

void encode() {
	cout << "is working" << endl;
	
}
void decode() {
	cout << " is working " << endl;

}
you could read this site's tutorial http://www.cplusplus.com/doc/tutorial/functions/
to learn more about function and its concept
1
2
3
4
5
6
...
else {
	cout << "Error, please type again" << endl;
	main(); // NEVER EVER call main() directly. Use a loop instead
}
return 0;


See here: http://stackoverflow.com/a/2128727
Topic archived. No new replies allowed.