int isaMUstring(char* sequence, int size) //function isaMUstring(char* sequence, int size)
{
int i,j;
for(i=0; i<size; i++)
{
if(sequence[i]=='M'||sequence[i]=='U'||sequence[i]=='I')
j=1;
else
j=0;
}
return j;
}
int canApplyRule1(char* sequence, int size) //function canApplyRule1(char* sequence, int size)
{
if(sequence[size-1]=='I')
return 1;
else
return 0;
}
int canApplyRule2(char* sequence, int size) //function canApplyRule2(char* sequence, int size)
{
if(sequence[0]=='M')
return 1;
else
return 0;
}
int main()
{
int i,size,num;
char*sequence;
string a;
cout<<"Enter the size you want:"<<endl; //ask for a size of the sequence
cin>>size;
sequence=new char[size];
ENTER:
cout<<"Please enter the sequence:"<<endl; //ask for the sequence
for(i=0; i<size; i++)
{
cin>>sequence[i];
}
if(!isaMUstring(sequence,size) || i > size ) //test if it is a MU string
{
cout<<"Invaild sequence"<<endl;
goto ENTER;
}
else //test whether Rule1 and Rule2 can be applied to it and notify the user
{
if(canApplyRule1(sequence,size))
cout<<"Can apply to rule1"<<endl;
if(canApplyRule2(sequence,size))
cout<<"Can apply to rule2"<<endl;
if(!canApplyRule1(sequence,size)&&!canApplyRule2(sequence,size))
cout<<"Both do not apply"<<endl;
}
if(canApplyRule1(sequence,size)||canApplyRule2(sequence,size)) //ask the user to choose a rule to apply
{
cout<<"Please choose the rule which can apply"<<endl;
cin>>num;
if(num==1)
{
char* arr=sequence[i];
int size=strlen(arr)+1;
char* old_ptr=arr;
arr=new char[size];
strcpy(arr,old_ptr);
strcat(arr, "U");
cout<<arr;
delete[] arr;
//print out the new sequence
}
if(num==2)
{
char*a=new char[size-1];
for(i=0;i<=size-1;i++)
{
a[i]=sequence[i+1];
}
for(i=0;i<=size;i++)
{
cout<<sequence[i];
}
for(i=0;i<=size-1;i++)
{
cout<<a[i]; //print out the new sequence
}
cout<<endl;
delete []a;
}
}
delete []sequence;
return 0;
}
this is a MU game, however there is an error when i try to compile it,
error C2440: 'initializing' : cannot convert from 'char' to 'char *'
the output is supposed to be when the user input a sequence ending with I the programs adds a U. However, the program must del the old sequence & generate a new sequence with a +1 size.
I cant seem to figure out whats wrong.
Hope someone could give me soem tips