I am completely new to programming, and I am teaching myself C++ via Dr. Bronson's book.
I have looked at other fixes and I don't understand them.
I am trying to do a project where I convert numbers to their phrase value. 1 = One, 2 = Two, etc. I cannot have spaces between one and two so I am outputting with no spaces. When I opened up the text file, I had only Asian characters in the file. Being a novice, my first concern was that I have been hacked. Anyhow, here is my code.
int main()
{
int i;
int length, mod, number1, number2,number3,numbera,numberb;
string str1;
string filename = "C:\\Users\\miram\\OneDrive\\Documents\\Visual Studio 2017\\CPlusPlusProjects\\Project Euler\\Files\\17.WordSum1.txt";
ofstream outFile;
outFile.open(filename.c_str());
if (outFile.fail())
{
cout << "\nThe file named " << filename << " did not successfully open."
<< "\Please check to make sure the file exists.";
}
for (i = 900; i <= 999; i++)
{
if (i <= 999)
{
length = (log(i) / log(10)) + 1;
cout << "i: " << i << " " << length << endl;
}
else if (i == 1000)
{
length = 4;
cout << "i: " << i << " " << length << endl;
}
if (length == 3)
{
number1 = i % 10;
numbera = i / 10;
number2 = numbera % 10;
numberb = i / 100;
number3 = numberb;
cout << "Number 3: " << number3 << endl;
cout << "Number 2: " << number2 << endl;
cout << "Number 1: " << number1 << endl;
}
switch (length)
{
case 4:
{
outFile << "OneThousand";
break;
}
case 3:
{
if (number3 == 1)
{
outFile << "OneHundredand";
}
else if (number3 == 2)
{
outFile << "TwoHundredand";
}
else if (number3 == 3)
{
outFile << "ThreeHundredand";
}
else if (number3 == 4)
{
outFile << "FourHundredand";
}
else if (number3 == 5)
{
outFile << "FiveHundredand";
}
else if (number3 == 6)
{
outFile << "SixHundredand";
}
else if (number3 == 7)
{
outFile << "SevenHundredand";
}
else if (number3 == 8)
{
outFile << "EightHundredand";
}
else if (number3 == 9);
{
outFile << "NineHundredand";
}
break;
}
}
}
return 0;
}