Errors in code

I dunno whats up with this code, it has errors but I look at it and cant find any, it gives you the length, last, and first number/letter of the input but it seems to think I'm missing a ; somewhere

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 <string>
using namespace std;

string first(string n)
{
string result;
result = n.substr(0, 1);
return result;
}

string last(string n)
{
string result;
result = n.substr(n.size() - 1, 1);
return result;
}

int lenth(string n)
{
int result;
result = n.size();
return result;
}
int main()
{
string a;
cout << "Input any value: ";
cin >> a;

cout << "First Digit: " << first(a) << endl;
cout << "Last Digit: " << last(a) << endl;
cout << "Amount Of Digits: " << lenth(a) << endl;
return 0;
}
Last edited on
closed account (28poGNh0)
You forgot the << operators

put
1
2
3
cout << "First Digit: " << first(a) << endl;
cout << "Last Digit: " << last(a) << endl;
cout << "Ammount Of Digits: " << lenth(a) << endl;


instead of

1
2
3
cout << "First Digit: " first(a) << endl;
cout << "Last Digit: " last(a) << endl;
cout << "Ammount Of Digits: " lenth(a) << endl;

Last edited on
That was just me screwing up the quote those are there in the code, its telling me >> doesn't match up with cin which I know damn well it does
Hmm Is there a reason I can't let the user define a string?
*edit* Ugh I forgot to #include <string> xD
Last edited on
you have two int main()in your code
This code is goulash ;)
I'm scrambling been up 21 hours now after i finish I will probably sleep for 2 days :P
You should lol ;)
There you go :)
Just to let the others to see what the code looked like before edit

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
59
60
61
62
#include <iostream>
#include <string>
using namespace std;

string first(string n)
{
string result;
result = n.substr(0, 1);
return result;
}

string last(string n)
{
string result;
result = n.substr(n.size(), 1);
return result;
}

int lenth(string n)
{
int result;
result = n.size();
return result;
}
int main()
{
string a;
cout << "Input any value: ";
#include <iostream>
using namespace std;

string first(string n)
{
string result;
result = n.substr(0, 1);
return result;
}

string last(string n)
{
string result;
result = n.substr(n.size(), 1);
return result;
}

int lenth(string n)
{
int result;
result = n.size();
return result;
}
int main()
{
string a;
cout << "Input any value: ";
cin >> a;

cout << "First Digit: " << first(a) << endl;
cout << "Last Digit: " << last(a) << endl;
cout << "Amount Of Digits: " << lenth(a) << endl;
return 0;
}
Topic archived. No new replies allowed.