I get the error when using cout in main function at end
#include "string"
#include "stdafx.h"
#include"iostream"
using namespace std;
string first[] = { "","one","two","three","four","five","six","seven","eight","nine","ten","eleven",
"twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen" };
string second[] = { "","","twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety" };
string lessThan100(int b)
{
if (b < 20) { return first[b]; }//accounts for numbers that don't follow pattern ie 11 to 19
return second[b / 10] + first[b % 10]; // dividing by 10 front number modding by 10 gives back number
}
string intToString(int a)
{
string output = "";
for (int x = log10(a); x >= 0; x = x - 3)
{
if (x >= 9)
{
int num = a / 1000000000;//dividing by a billion gives the # of billions
if (num<99) { return "error number too large"; }
output = output + lessThan100(num) + " billion ";
}
else if (x >= 6)
{
int num = a % 1000000000 / 1000000; //modding by a billion leaves the millions dividing by million gives # of millions
output = output + lessThan100(num) + " million ";
}
else if (x >= 3)
{
string over100 = "";
int num = a % 1000000 / 1000;//modding by a million leaves the thousands dividing by a thousand gives # of thousands
if (num >= 100) { over100 = first[num / 100] + " hundred "; }//we can have more than 99 thousand so we account for that
output = output + over100 + lessThan100(num) + " thousand ";
}
else if (x >= 0)
{
string over100 = "";
int num = a % 1000;//moding by 1000 gives hundreds
if (num >= 100) { over100 = first[num / 100] + " hundred "; }//accounts for number higher than 99
output = output + over100 + lessThan100(num);
}
}
}
int main()
{
int number = 19;
string word = intToString(19);
cout << word;
return 0;
}
I get this error binary '<<': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion). The program runs fine when I remove cout << word; I really just want to see if intToString() is working.