hiroler
11-25-2004, 04:22 AM
Hey guys my program is to read in numbers from input.txt, compute the complex number operation, then output the solutions to output.txt until end of file marker (control z). For some reason it's only outputing 1 line to output.txt, instead of all 5.
int main()
{
int i1, i2, i3 ,i4;
char op;
ifstream in("input.txt", ios::in);
do
{
in >> i1 >> i2 >> op >> i3 >> i4;
ofstream out("output.txt", ios::out);
if (op == '*')
{
out<<endl<< "(" << i1 << " + " << i2 << "i" << ") " << op << " (" << i3 << " + " << i4 << "i" << ")" << " = ";
out<< "(" << (i1*i3)-(i2*i4) << " + " << (i2*i3)+(i1*i4) << ")";
}
else if (op == '+')
{
out<<endl<< "(" << i1 << " + " << i2 << "i" << ") " << op << " (" << i3 << " + " << i4 << "i" << ")" << " = ";
out<< "(" << i1+i3 << " + " << i2+i4 << "i)";
}
else if (op == '-' && i2-i4<0)
{
int x = abs(i2-i4);
out<<endl<< "(" << i1 << " - " << i2 << "i" << ") " << op << " (" << i3 << " - " << i4 << "i" << ")" << " = ";
out<< "(" << i1-i3 << " + " << x << "i)";
}
else if (op == '-' && i2-i4>=0)
{
out<<endl<< "(" << i1 << " - " << i2 << "i" << ") " << op << " (" << i3 << " - " << i4 << "i" << ")" << " = "; out<< "(" << i1-i3 << " - " << i2-i4 << "i)";
}
}
while( !in.eof( ) ) ;
system("pause");
return 0;
}
With this do/while loop or with just while at the top it outputs; (1 + -5i) * (1 + 5i) = (26 + 0) to the 2nd line of output.txt with this as input.txt;
2 3 - 4 5
2 3 * 4 1
3 2 + 7 -8
3 2 * 7 -8
1-5 * 1 5
Anybody want to plunge into this and tell me what im doing wrong? I know its the day before turkey day so you probably have better stuff to do but this is due at midnight thursday night =)
i thank ya-
kyle
int main()
{
int i1, i2, i3 ,i4;
char op;
ifstream in("input.txt", ios::in);
do
{
in >> i1 >> i2 >> op >> i3 >> i4;
ofstream out("output.txt", ios::out);
if (op == '*')
{
out<<endl<< "(" << i1 << " + " << i2 << "i" << ") " << op << " (" << i3 << " + " << i4 << "i" << ")" << " = ";
out<< "(" << (i1*i3)-(i2*i4) << " + " << (i2*i3)+(i1*i4) << ")";
}
else if (op == '+')
{
out<<endl<< "(" << i1 << " + " << i2 << "i" << ") " << op << " (" << i3 << " + " << i4 << "i" << ")" << " = ";
out<< "(" << i1+i3 << " + " << i2+i4 << "i)";
}
else if (op == '-' && i2-i4<0)
{
int x = abs(i2-i4);
out<<endl<< "(" << i1 << " - " << i2 << "i" << ") " << op << " (" << i3 << " - " << i4 << "i" << ")" << " = ";
out<< "(" << i1-i3 << " + " << x << "i)";
}
else if (op == '-' && i2-i4>=0)
{
out<<endl<< "(" << i1 << " - " << i2 << "i" << ") " << op << " (" << i3 << " - " << i4 << "i" << ")" << " = "; out<< "(" << i1-i3 << " - " << i2-i4 << "i)";
}
}
while( !in.eof( ) ) ;
system("pause");
return 0;
}
With this do/while loop or with just while at the top it outputs; (1 + -5i) * (1 + 5i) = (26 + 0) to the 2nd line of output.txt with this as input.txt;
2 3 - 4 5
2 3 * 4 1
3 2 + 7 -8
3 2 * 7 -8
1-5 * 1 5
Anybody want to plunge into this and tell me what im doing wrong? I know its the day before turkey day so you probably have better stuff to do but this is due at midnight thursday night =)
i thank ya-
kyle