Sep 2, 2013 at 6:47pm UTC
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 Sep 2, 2013 at 7:40pm UTC
Sep 2, 2013 at 6:52pm UTC
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 Sep 2, 2013 at 6:53pm UTC
Sep 2, 2013 at 7:03pm UTC
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
Sep 2, 2013 at 7:11pm UTC
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 Sep 2, 2013 at 7:13pm UTC
Sep 2, 2013 at 7:17pm UTC
you have two int main()
in your code
Sep 2, 2013 at 7:40pm UTC
I'm scrambling been up 21 hours now after i finish I will probably sleep for 2 days :P