This is the code:
Code:
#include <iostream.h>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
int x = 0;
string num;
cout << "Input a Number.\n";
cin >> num;
x = length(num);
string numLast = num.substr(x, -1);
switch (numLast)
{
case '1': cout << num << "st.\n";
break;
case '2': cout << num << "nd.\n";
break;
case '3': cout << num << "rd.\n";
default: cout << "\n" << num << "th.\n";
}
system("PAUSE");
return 0;
}
These are the errors:
1. implicit declaration of function `int length(...)'
2. warning: cannot pass objects of type `string' through `...'
3. switch quantity not an integer
4. case label `'1'' not within a switch statement
5. break statement not within loop or switch
etc.
I know I'm being annoying, but it's just that PHP's messed up my C++ comprehension. PHP code would look like this:
Code:
function nSufx ($n)
{
switch (substr($n,-1))
{
case 1: return $n.'st';
case 2: return $n.'nd';
case 3: return $n.'rd';
default: return $n.'th';
}
}
Just in case you were wondering why my code sucks.