Theres a bug and i need to fix it! error message and '10' function does not work

#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;

void five(char num1, ofstream& fout1);
void six(char num2, ofstream& fout2);
void seven(char num3, ofstream& fout3);
void eight(char num4, ofstream& fout4);
void nine(char num5, ofstream& fout5);
void ten(char num6, ofstream& fout6);

int main()
{
char ch;
char yes;

ofstream outDataFile;

outDataFile.open("outDataFile.txt");
do
{
cout << "Please enter an integer X, as 5 <= X <= 10 and press <ENTER>: " << endl;
ch = cin.get();

while (ch < '5' || ch > '10' || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z'))
{
cout << "ERROR: Please enter an integer X, as 5 <= X <= 10 and press <ENTER>: " << endl;;
ch = cin.get();
}

if (ch == '5')
{
outDataFile << ch << endl;
five(ch, outDataFile);
}
else if (ch == '6')
{
outDataFile << ch << endl;
six(ch, outDataFile);
}
else if (ch == '7')
{
outDataFile << ch << endl;
seven(ch, outDataFile);
}
else if (ch == '8')
{
outDataFile << ch << endl;
eight(ch, outDataFile);
}
else if (ch == '9')
{
outDataFile << ch << endl;
nine(ch, outDataFile);
}
else if (ch == '10')
{
outDataFile << ch << endl;
ten(ch, outDataFile);
}

cout << "Y or y to continue, if you want to EXIT press any key." << endl;

cin >> yes;
} while (yes == 'Y' || yes == 'y');

cout << "Thank you and Good-Bye" << endl;

outDataFile.close();
system("pause");
return 0;
}
void five(char num1, ofstream& fout1)
{
int i = 1;

cout << "Your numbers squared are:\n";
fout1 << "Your numbers squared are:\n";
while (i <= 5)
{
cout <<"***" << i * i;
fout1 << "***" << i * i;
i++;
}
cout << endl;
fout1 << endl;

if (1 % 2 == 0)
i = 1;
else
i = 1 + 1;

cout << "The even numbers are:\n";
fout1 << "The even numbers are:\n";
while (i <= 5)
{
cout << "***" << i * i;
fout1 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout1 << endl;

if (1 % 2 == 1)
i = 1;
else
i = 1 + 1;

cout << "The odd numbers are:\n";
fout1 << "The odd numbers are:\n";
while (i <= 5)
{
cout << "***" << i * i;
fout1 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout1 << endl;

cout << "----------------------------" << endl;
fout1 << "----------------------------" << endl;
}
void six(char num2, ofstream& fout2)
{
int i = 1;

cout << "Your numbers squared are:\n";
fout2 << "Your numbers squared are:\n";
while (i <= 6)
{
cout << "***" << i * i;
fout2 << "***" << i * i;
i++;
}
cout << endl;
fout2 << endl;

if (1 % 2 == 0)
i = 1;
else
i = 1 + 1;

cout << "The even numbers are:\n";
fout2 << "The even numbers are:\n";
while (i <= 6)
{
cout << "***" << i * i;
fout2 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout2 << endl;

if (1 % 2 == 1)
i = 1;
else
i = 1 + 1;

cout << "The odd numbers are:\n";
fout2 << "The odd numbers are:\n";
while (i <= 6)
{
cout << "***" << i * i;
fout2 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout2 << endl;

cout << "----------------------------" << endl;
fout2 << "----------------------------" << endl;
}
void seven(char num3, ofstream& fout3)
{
int i = 1;

cout << "Your numbers squared are:\n";
fout3 << "Your numbers squared are:\n";
while (i <= 7)
{
cout << "***" << i * i;
fout3 << "***" << i * i;
i++;
}
cout << endl;
fout3 << endl;

if (1 % 2 == 0)
i = 1;
else
i = 1 + 1;

cout << "The even numbers are:\n";
fout3 << "The even numbers are:\n";
while (i <= 7)
{
cout << "***" << i * i;
fout3 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout3 << endl;

if (1 % 2 == 1)
i = 1;
else
i = 1 + 1;

cout << "The odd numbers are:\n";
fout3 << "The odd numbers are:\n";
while (i <= 7)
{
cout << "***" << i * i;
fout3 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout3 << endl;

cout << "----------------------------" << endl;
fout3 << "----------------------------" << endl;
}
void eight(char num4, ofstream& fout4)
{
int i = 1;

cout << "Your numbers squared are:\n";
fout4 << "Your numbers squared are:\n";
while (i <= 8)
{
cout << "***" << i * i;
fout4 << "***" << i * i;
i++;
}
cout << endl;
fout4 << endl;

if (1 % 2 == 0)
i = 1;
else
i = 1 + 1;

cout << "The even numbers are:\n";
fout4 << "The even numbers are:\n";
while (i <= 8)
{
cout << "***" << i * i;
fout4 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout4 << endl;

if (1 % 2 == 1)
i = 1;
else
i = 1 + 1;

cout << "The odd numbers are:\n";
fout4 << "The odd numbers are:\n";
while (i <= 8)
{
cout << "***" << i * i;
fout4 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout4 << endl;

cout << "----------------------------" << endl;
fout4 << "----------------------------" << endl;
}
void nine(char num5, ofstream& fout5)
{
int i = 1;

cout << "Your numbers squared are:\n";
fout5 << "Your numbers squared are:\n";
while (i <= 9)
{
cout << "***" << i * i;
fout5 << "***" << i * i;
i++;
}
cout << endl;
fout5 << endl;

if (1 % 2 == 0)
i = 1;
else
i = 1 + 1;

cout << "The even numbers are:\n";
fout5 << "The even numbers are:\n";
while (i <= 9)
{
cout << "***" << i * i;
fout5 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout5 << endl;

if (1 % 2 == 1)
i = 1;
else
i = 1 + 1;

cout << "The odd numbers are:\n";
fout5 << "The odd numbers are:\n";
while (i <= 9)
{
cout << "***" << i * i;
fout5 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout5 << endl;

cout << "----------------------------" << endl;
fout5 << "----------------------------" << endl;

}
void ten(char num6, ofstream& fout6)
{
int i = 1;

cout << "Your numbers squared are:\n";
fout6 << "Your numbers squared are:\n";
while (i <= 10)
{
cout << "***" << i * i;
fout6 << "***" << i * i;
i++;
}
cout << endl;
fout6 << endl;

if (1 % 2 == 0)
i = 1;
else
i = 1 + 1;

cout << "The even numbers are:\n";
fout6 << "The even numbers are:\n";
while (i <= 10)
{
cout << "***" << i * i;
fout6 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout6 << endl;

if (1 % 2 == 1)
i = 1;
else
i = 1 + 1;

cout << "The odd numbers are:\n";
fout6 << "The odd numbers are:\n";
while (i <= 10)
{
cout << "***" << i * i;
fout6 << "***" << i * i;
i = i + 2;
}
cout << endl;
fout6 << endl;

cout << "----------------------------" << endl;
fout6 << "----------------------------" << endl;
}





stick this in code tags and be a bit more specific please.

that's a hell of a lot of code duplication, all the functions seem the same except for an integer??

You could have a single function and pass in the user's choice.
1
2
else if (ch == '10')
ch > '10'

Say, how many digits there in number 10? And how do you intend to fit in variable containing only one character? And why didn't you noticed compiler screaming bloody murder about multicharacter literal?
warning: multi-character character constant [-Wmultichar]
(If it doesn't scream at you either configure it properly or get a better compiler)
'10' is not a char . Since it has two charACTERS.
'10' is not a char
Yes. It is an int, actually.
Topic archived. No new replies allowed.