Hi ..
I have this program, its reding correctly but its not doing what i want
i.e. it suppose to read the input file and call the functions according to the action saved in the file
this is the problem :
#include <iostream>
#include <Fstream>
using namespace std;
void move();
void turn();
void turnOff();
int x, y;
char a, d;
int A[30][30];
int main()
{
ifstream infile;
infile.unsetf( ios::skipws );
infile.open( "input.txt" );
infile>>x>>y;
infile>>d;
if( x<0 || y<0 )
{
cout<<"the parameters should be positive!/n/n";
exit(0);
}
else
A[x][y];
cout<<"BEGINNING-OF-PROGRAM\n"<<"\n\nThe initial Position: ("<<x<<", "<<y<<")\n";
cout<<"The initial Direction: "<<d<<endl<<endl;
while( !infile.eof() )
{
infile>>a;
switch(a){
case'm':case'M':do
{//********** HERE IS THE PROBLEM ***************
infile>>a;
if( a=='o' || a=='v' || a=='e' )
{
move();
break;
}
else
{
cout<<"\n1)Error in the input file! ";
return 0;
}
}while( a!=';');break;
case't':case'T':do
{
infile>>a;
if( a=='u' || a=='r' || a=='n' )
{
if( a==';' )
{
turn();
break;
}
else if( a=='O' || a=='f' || a=='f')
{
turnOff();
break;
}
}
else
{
cout<<"\nError in the input file! ";
return 0;
}
}while( a!=';');break;
default:break;
}//*********************
}
cout<<"END-OF-PROGRAM\n"<<"\n\nThe Final Position: ("<<x<<", "<<y<<")\n";
cout<<"The Fial Direction: "<<d<<endl<<endl;
infile.close();
return 0;
}
void move()
{
cout<<"Move\n";
}
void turn()
{
cout<<"Turn\n";
}
void turnOff()
{
cout<<"TurnOff\n";
}
the input file :
4 5
E
move;
move;
move;
turn;
turn;
move;
turn;
move;
move;
move;
turnOff;
Please somebody HELP!!!!:S